Skip to content

Commit f7bfaf0

Browse files
blazonceksofthack007
authored andcommitted
Possible bugfix for wled#3609 wled#3616
1 parent 1f65843 commit f7bfaf0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

wled00/FX_fcn.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,14 @@ Segment& Segment::operator= (Segment &&orig) noexcept {
201201
}
202202

203203
bool Segment::allocateData(size_t len) {
204-
if (data && _dataLen >= len) {
205-
if (call == 0) memset(data, 0, len); // WLEDMM: clear data when SEGENV.call==0
206-
return true; //already allocated
204+
// WLEDMM
205+
if (data && _dataLen >= len) { // already allocated enough (reduce fragmentation)
206+
if ((call == 0) && (len > 0)) memset(data, 0, len); // erase buffer if called during effect initialisation
207+
return true;
207208
}
208209
//DEBUG_PRINTF("allocateData(%u) start %d, stop %d, vlen %d\n", len, start, stop, virtualLength());
209210
deallocateData();
211+
if (len == 0) return false; // nothing to do
210212
if (Segment::getUsedSegmentData() + len > MAX_SEGMENT_DATA) return false; //not enough memory
211213
// do not use SPI RAM on ESP32 since it is slow
212214
//#if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)

0 commit comments

Comments
 (0)