fx functions: avoid memory corruption
* PSRAM_Allocator was missing the "reallocate" method, which lead to undefined behaviour when dynamic JSON doc needed to grow/shrink * Segment::setUpLeds() quickfix for length() == 0 (should not happen, but it did happen for me once) * leds in PSRAM causes major slowdown on wrover boards - disabled.
This commit is contained in:
parent
a717238f76
commit
e4a9f115cb
@ -199,13 +199,14 @@ void Segment::setUpLeds() {
|
||||
#else
|
||||
leds = &Segment::_globalLeds[start];
|
||||
#endif
|
||||
else if (!leds) {
|
||||
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
||||
if (psramFound())
|
||||
leds = (CRGB*)ps_malloc(sizeof(CRGB)*length());
|
||||
else
|
||||
#endif
|
||||
leds = (CRGB*)malloc(sizeof(CRGB)*length());
|
||||
else if (leds == nullptr) {
|
||||
//#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_PSRAM)
|
||||
//if (psramFound())
|
||||
// leds = (CRGB*)ps_malloc(sizeof(CRGB)*length()); // softhack007 disabled; putting leds into psram leads to horrible slowdown on WROVER boards
|
||||
//else
|
||||
//#endif
|
||||
if (length() > 0) //softhack007 quickfix - avoid malloc(0) which is undefined behaviour (should not happen, but i've seen it)
|
||||
leds = (CRGB*)malloc(sizeof(CRGB)*length());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,6 +151,10 @@ struct PSRAM_Allocator {
|
||||
if (psramFound()) return ps_malloc(size); // use PSRAM if it exists
|
||||
else return malloc(size); // fallback
|
||||
}
|
||||
void* reallocate(void* ptr, size_t new_size) {
|
||||
if (psramFound()) return ps_realloc(ptr, new_size); // use PSRAM if it exists
|
||||
else return realloc(ptr, new_size); // fallback
|
||||
}
|
||||
void deallocate(void* pointer) {
|
||||
free(pointer);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user