diff --git a/wled00/FX.h b/wled00/FX.h index 955203a3..6fec67c8 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -941,8 +941,8 @@ class WS2812FX { // 96 bytes show_callback _callback; - uint16_t* customMappingTable; - uint16_t customMappingSize; + uint16_t* customMappingTable = nullptr; + uint16_t customMappingSize = 0; /*uint32_t*/ unsigned long _lastShow; // WLEDMM avoid losing precision diff --git a/wled00/FX_2Dfcn.cpp b/wled00/FX_2Dfcn.cpp index c5c77bb4..910405bf 100644 --- a/wled00/FX_2Dfcn.cpp +++ b/wled00/FX_2Dfcn.cpp @@ -37,7 +37,8 @@ void WS2812FX::setUpMatrix() { #ifndef WLED_DISABLE_2D // erase old ledmap, just in case. - if (customMappingTable != nullptr) delete[] customMappingTable; + //if (customMappingTable != nullptr) delete[] customMappingTable; + if (customMappingTable != nullptr) free(customMappingTable); customMappingTable = nullptr; customMappingSize = 0; @@ -68,7 +69,9 @@ void WS2812FX::setUpMatrix() { return; } - customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight]; + //customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight]; + if (nullptr != customMappingTable) free(customMappingTable); + customMappingTable = (uint16_t *) calloc(Segment::maxWidth * Segment::maxHeight, sizeof(uint16_t)); if (customMappingTable != nullptr) { customMappingSize = Segment::maxWidth * Segment::maxHeight; diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 2e36e32e..ccd7656e 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -591,7 +591,8 @@ class JMapC { if (jVectorMap.size() > 0) { USER_PRINTLN("delete jVectorMap"); for (size_t i=0; i0 && doc[F("height")]>0) { - Segment::maxWidth = doc[F("width")];; - Segment::maxHeight = doc[F("height")];; + Segment::maxWidth = doc[F("width")]; + Segment::maxHeight = doc[F("height")]; resetSegments(true); //WLEDMM not makeAutoSegments() as we only want to change bounds } customMappingSize = map.size(); - customMappingTable = new uint16_t[customMappingSize]; + if (nullptr != customMappingTable) free(customMappingTable); + //customMappingTable = new uint16_t[customMappingSize]; + customMappingTable = (uint16_t *) calloc(customMappingSize+1, sizeof(uint16_t)); // softhack007 use calloc / free, as they behave better when heap is low + if (nullptr == customMappingTable) { // WLEDMM handle out-of-memory + USER_PRINTF("deserializeMap(): cannot alloate %d bytes for customMappingTable[]\n", sizeof(uint16_t) * (customMappingSize+1)); + customMappingSize = 0; + loadedLedmap = 0; + releaseJSONBufferLock(); + return false; //if not enough memory - just exit + } for (uint16_t i=0; iget(); + if (!buffer) return false; //out of memory + + wsBuf->lock(); // protect buffer from being cleaned by another WS instance buffer[0] = 'L'; buffer[1] = 1; //version #ifndef WLED_DISABLE_2D @@ -201,6 +217,8 @@ static bool sendLiveLedsWs(uint32_t wsClient) // WLEDMM added "static" } wsc->binary(wsBuf); + wsBuf->unlock(); // un-protect buffer + ws._cleanBuffers(); // cleans up if the message is not added to any clients. return true; }