(experimental) use malloc/realloc for customMappingTable

if this works better, we should cherry-pick it into mdev.
This commit is contained in:
Frank
2023-05-21 19:38:04 +02:00
parent 894fdce4b5
commit fc193408d8
3 changed files with 28 additions and 8 deletions

View File

@@ -66,8 +66,17 @@ void WS2812FX::setUpMatrix() {
//WLEDMM recreate customMappingTable if more space needed
if (Segment::maxWidth * Segment::maxHeight > customMappingTableSize) {
USER_PRINTF("setupmatrix customMappingTable alloc %d from %d\n", Segment::maxWidth * Segment::maxHeight, customMappingTableSize);
if (customMappingTable != nullptr) delete[] customMappingTable;
customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight];
//if (customMappingTable != nullptr) delete[] customMappingTable;
//customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight];
// don't use new / delete
if (customMappingTable != nullptr) { // resize
customMappingTable = (uint16_t*) reallocf(customMappingTable, sizeof(uint16_t) * Segment::maxWidth * Segment::maxHeight); // reallocf will free memory if it cannot resize
}
if (customMappingTable == nullptr) { // second try
DEBUG_PRINTLN("setUpMatrix: trying to get fresh memory block.");
customMappingTable = (uint16_t*) calloc(Segment::maxWidth * Segment::maxHeight, sizeof(uint16_t));
if (customMappingTable == nullptr) DEBUG_PRINTLN("setUpMatrix: alloc failed");
}
if (customMappingTable != nullptr) customMappingTableSize = Segment::maxWidth * Segment::maxHeight;
}
@@ -142,6 +151,7 @@ void WS2812FX::setUpMatrix() {
DEBUG_PRINTLN();
#endif
} else { // memory allocation error
customMappingTableSize = 0;
DEBUG_PRINTLN(F("Ledmap alloc error."));
isMatrix = false;
panels = 0;