Skip to content

Commit

Permalink
Fix for #3889
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Apr 9, 2024
1 parent ba9ce4a commit 58e8346
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
7 changes: 4 additions & 3 deletions wled00/FX_2Dfcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ void WS2812FX::setUpMatrix() {

customMappingSize = 0; // prevent use of mapping if anything goes wrong

if (customMappingTable == nullptr) customMappingTable = new uint16_t[getLengthTotal()];
if (customMappingTable) delete[] customMappingTable;
customMappingTable = new uint16_t[getLengthTotal()];

if (customMappingTable != nullptr) {
if (customMappingTable) {
customMappingSize = getLengthTotal();

// fill with empty in case we don't fill the entire matrix
Expand Down Expand Up @@ -138,7 +139,7 @@ void WS2812FX::setUpMatrix() {
DEBUG_PRINTLN();
#endif
} else { // memory allocation error
DEBUG_PRINTLN(F("Ledmap alloc error."));
DEBUG_PRINTLN(F("ERROR 2D LED map allocation error."));
isMatrix = false;
panels = 0;
panel.clear();
Expand Down
24 changes: 14 additions & 10 deletions wled00/FX_fcn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1656,19 +1656,23 @@ bool WS2812FX::deserializeMap(uint8_t n) {
return false; // if file does not load properly then exit
}

DEBUG_PRINT(F("Reading LED map from ")); DEBUG_PRINTLN(fileName);

if (customMappingTable == nullptr) customMappingTable = new uint16_t[getLengthTotal()];

JsonObject root = pDoc->as<JsonObject>();
JsonArray map = root[F("map")];
if (!map.isNull() && map.size()) { // not an empty map
customMappingSize = min((unsigned)map.size(), (unsigned)getLengthTotal());
for (unsigned i=0; i<customMappingSize; i++) customMappingTable[i] = (uint16_t) (map[i]<0 ? 0xFFFFU : map[i]);
if (customMappingTable) delete[] customMappingTable;
customMappingTable = new uint16_t[getLengthTotal()];

if (customMappingTable) {
DEBUG_PRINT(F("Reading LED map from ")); DEBUG_PRINTLN(fileName);
JsonObject root = pDoc->as<JsonObject>();
JsonArray map = root[F("map")];
if (!map.isNull() && map.size()) { // not an empty map
customMappingSize = min((unsigned)map.size(), (unsigned)getLengthTotal());
for (unsigned i=0; i<customMappingSize; i++) customMappingTable[i] = (uint16_t) (map[i]<0 ? 0xFFFFU : map[i]);
}
} else {
DEBUG_PRINTLN(F("ERROR LED map allocation error."));
}

releaseJSONBufferLock();
return true;
return (customMappingSize > 0);
}

uint16_t IRAM_ATTR WS2812FX::getMappedPixelIndex(uint16_t index) {
Expand Down

0 comments on commit 58e8346

Please sign in to comment.