From 9832fbe0422dbc77ebd96ba7eeaef2979732a068 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Tue, 8 Aug 2023 20:40:19 +0200 Subject: [PATCH] Segment reset --- wled00/FX.h | 5 ++++- wled00/FX_fcn.cpp | 9 +++++---- wled00/wled.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wled00/FX.h b/wled00/FX.h index a38aac33..029afa60 100644 --- a/wled00/FX.h +++ b/wled00/FX.h @@ -487,6 +487,9 @@ typedef struct Segment { _t(nullptr) { //refreshLightCapabilities(); + #ifdef WLED_DEBUG + //Serial.printf("-- Creating segment: %p\n", this); + #endif } Segment(uint16_t sStartX, uint16_t sStopX, uint16_t sStartY, uint16_t sStopY) : Segment(sStartX, sStopX) { @@ -499,7 +502,7 @@ typedef struct Segment { ~Segment() { #ifdef WLED_DEBUG - Serial.printf("-- Destroying segment: %p\n", this); + //Serial.printf("-- Destroying segment: %p\n", this); //if (name) Serial.printf(" %s (%p)", name, name); //if (data) Serial.printf(" %d (%p)", (int)_dataLen, data); //Serial.println(); diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index d89a37ff..513b5c2f 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -175,7 +175,7 @@ bool Segment::allocateData(size_t len) { void Segment::deallocateData() { if (!data) return; - DEBUG_PRINTF("--- Released data (%d/%d): %p -> %p\n", _dataLen, Segment::getUsedSegmentData(), this, data); + DEBUG_PRINTF("--- Released data (%p): %d/%d -> %p\n", this, _dataLen, Segment::getUsedSegmentData(), data); free(data); data = nullptr; // WARNING it looks like we have a memory leak somewhere @@ -193,7 +193,6 @@ void Segment::deallocateData() { void Segment::resetIfRequired() { if (!reset) return; //DEBUG_PRINTF("-- Segment reset: %p\n", this); - startTransition(0); // stop pending transition deallocateData(); next_time = 0; step = 0; call = 0; aux0 = 0; aux1 = 0; reset = false; @@ -307,7 +306,7 @@ void Segment::startTransition(uint16_t dur) { if (_dataLen > 0 && data) { _t->_tmpSeg._dataT = (byte *)malloc(_dataLen); if (_t->_tmpSeg._dataT) { - //DEBUG_PRINTF("-- Allocated duplicate data (%d): %p\n", _dataLen, _t->_tmpSeg._dataT); + DEBUG_PRINTF("-- Allocated duplicate data (%d): %p\n", _dataLen, _t->_tmpSeg._dataT); memcpy(_t->_tmpSeg._dataT, data, _dataLen); _t->_tmpSeg._dataLenT = _dataLen; } @@ -321,7 +320,7 @@ void Segment::stopTransition() { //DEBUG_PRINTF("-- Stopping transition: %p\n", this); if (_t) { if (_t->_tmpSeg._dataT && _t->_tmpSeg._dataLenT > 0) { - //DEBUG_PRINTF("-- Released duplicate data (%d): %p\n", _t->_tmpSeg._dataLenT, _t->_tmpSeg._dataT); + DEBUG_PRINTF("-- Released duplicate data (%d): %p\n", _t->_tmpSeg._dataLenT, _t->_tmpSeg._dataT); free(_t->_tmpSeg._dataT); _t->_tmpSeg._dataT = nullptr; } @@ -380,6 +379,7 @@ void Segment::restoreSegenv(tmpsegd_t *tmpSeg) { _t->_tmpSeg._stepT = step; _t->_tmpSeg._callT = call; if (_t->_tmpSeg._dataT != data) DEBUG_PRINTF("--- data re-allocated: (%p) %p -> %p\n", this, _t->_tmpSeg._dataT, data); + //if (_t->_tmpSeg._dataT && _t->_tmpSeg._dataLenT > 0) free(_t->_tmpSeg._dataT); // not good _t->_tmpSeg._dataT = data; // sometimes memory gets re-allocated (!! INVESTIGATE WHY !!) _t->_tmpSeg._dataLenT = _dataLen; // sometimes memory gets re-allocated (!! INVESTIGATE WHY !!) } @@ -557,6 +557,7 @@ void Segment::setMode(uint8_t fx, bool loadDefaults) { sOpt = extractModeDefaults(fx, "mY"); if (sOpt >= 0) mirror_y = (bool)sOpt; // NOTE: setting this option is a risky business sOpt = extractModeDefaults(fx, "pal"); if (sOpt >= 0) setPalette(sOpt); //else setPalette(0); } + markForReset(); stateChanged = true; // send UDP/WS broadcast } } diff --git a/wled00/wled.h b/wled00/wled.h index 703776cd..cae5d732 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2308050 +#define VERSION 2308080 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG