code robustness improvements plus minor speedup

* make  XY() and _setPixelColorXY_raw() const (minor speedup)
* segment is a struct not a class: friend class Segment --> friend struct Segment
* fix missing braces around two macros
* use non-throwing "new" where possible
* improve robustness of transition code
This commit is contained in:
Frank
2025-01-07 15:09:29 +01:00
parent 32b22636fa
commit f8a673ce81
5 changed files with 21 additions and 21 deletions

View File

@@ -68,7 +68,7 @@ void WS2812FX::setUpMatrix() {
if (!needLedMap) size = 0; // softhack007
USER_PRINTF("setupmatrix customMappingTable alloc %d from %d\n", size, customMappingTableSize);
//if (customMappingTable != nullptr) delete[] customMappingTable;
//customMappingTable = new uint16_t[size];
//customMappingTable = new(std::nothrow) uint16_t[size];
// don't use new / delete
if ((size > 0) && (customMappingTable != nullptr)) { // resize
@@ -118,7 +118,7 @@ void WS2812FX::setUpMatrix() {
JsonArray map = doc.as<JsonArray>();
gapSize = map.size();
if (!map.isNull() && (gapSize > 0) && gapSize >= customMappingSize) { // not an empty map //softhack also check gapSize>0
gapTable = new int8_t[gapSize];
gapTable = new(std::nothrow) int8_t[gapSize];
if (gapTable) for (size_t i = 0; i < gapSize; i++) {
gapTable[i] = constrain(map[i], -1, 1);
}