Bug fix segment view, use ledmapMaxSize (TroyHack)

This commit is contained in:
Ewoud
2023-06-08 18:34:10 +02:00
parent b332204978
commit 8d43af6acc
7 changed files with 1210 additions and 1193 deletions

View File

@@ -110,13 +110,14 @@ Segment::Segment(const Segment &orig) {
//WLEDMM: recreate ledsrgb if more space needed (will not free ledsrgb!)
void Segment::allocLeds() {
if (!ledsrgb || sizeof(CRGB)*length() > ledsrgbSize) {
USER_PRINTF("allocLeds %d from %d\n", sizeof(CRGB)*length(), ledsrgb?ledsrgbSize:0);
ledsrgb = (CRGB*)malloc(sizeof(CRGB)*length());
ledsrgbSize = ledsrgb?sizeof(CRGB)*length():0;
uint16_t size = sizeof(CRGB)*MAX(length(), ledmapMaxSize); //TroyHack
if (!ledsrgb || size > ledsrgbSize) {
USER_PRINTF("allocLeds %d from %d\n", size, ledsrgb?ledsrgbSize:0);
ledsrgb = (CRGB*)malloc(size);
ledsrgbSize = ledsrgb?size:0;
}
else {
USER_PRINTF("reuse Leds %d from %d\n", sizeof(CRGB)*length(), ledsrgb?ledsrgbSize:0);
USER_PRINTF("reuse Leds %d from %d\n", size, ledsrgb?ledsrgbSize:0);
}
}
@@ -1367,6 +1368,7 @@ uint8_t * Segment::getAudioPalette(int pal) {
//WLEDMM from util.cpp
// enumerate all ledmapX.json files on FS and extract ledmap names if existing
void WS2812FX::enumerateLedmaps() {
ledmapMaxSize = 0;
ledMaps = 1;
for (int i=1; i<10; i++) {
char fileName[33];
@@ -1392,7 +1394,6 @@ void WS2812FX::enumerateLedmaps() {
f.find("\"n\":");
char name[33];
f.readBytesUntil('\n', name, sizeof(name));
USER_PRINTF("enumerateLedmaps %s %s\n", fileName, name);
size_t len = 0;
if (name != nullptr) {
@@ -1409,6 +1410,18 @@ void WS2812FX::enumerateLedmaps() {
ledmapNames[i-1] = new char[len+1];
if (ledmapNames[i-1]) strlcpy(ledmapNames[i-1], tmp, 33);
}
//WLEDMM calc ledmapMaxSize (TroyHack)
char dim[33];
f.find("\"width\":");
f.readBytesUntil('\n', dim, sizeof(dim)); //hack: use fileName as we have this allocated already
uint16_t maxWidth = atoi(dim);
f.find("\"height\":");
f.readBytesUntil('\n', dim, sizeof(dim));
uint16_t maxHeight = atoi(dim);
ledmapMaxSize = MAX(ledmapMaxSize, maxWidth * maxHeight);
USER_PRINTF("enumerateLedmaps %s %s (%dx%d -> %d)\n", fileName, name, maxWidth, maxHeight, ledmapMaxSize);
}
f.close();
releaseJSONBufferLock();
@@ -2196,7 +2209,6 @@ bool WS2812FX::deserializeMap(uint8_t n) {
f.readBytesUntil('\n', fileName, sizeof(fileName)); //hack: use fileName as we have this allocated already
uint16_t maxWidth = atoi(fileName);
f.find("\"height\":");
f.readBytesUntil('\n', fileName, sizeof(fileName));
uint16_t maxHeight = atoi(fileName);
@@ -2214,10 +2226,11 @@ bool WS2812FX::deserializeMap(uint8_t n) {
//WLEDMM recreate customMappingTable if more space needed
if (Segment::maxWidth * Segment::maxHeight > customMappingTableSize) {
USER_PRINTF("deserializemap customMappingTable alloc %d from %d\n", Segment::maxWidth * Segment::maxHeight, customMappingTableSize);
uint32_t size = MAX(ledmapMaxSize, Segment::maxWidth * Segment::maxHeight);//TroyHack
USER_PRINTF("deserializemap customMappingTable alloc %d from %d\n", size, customMappingTableSize);
if (customMappingTable != nullptr) delete[] customMappingTable;
customMappingTable = new uint16_t[Segment::maxWidth * Segment::maxHeight];
if (customMappingTable != nullptr) customMappingTableSize = Segment::maxWidth * Segment::maxHeight;
customMappingTable = new uint16_t[size];
if (customMappingTable != nullptr) customMappingTableSize = size;
}
if (customMappingTable != nullptr) {