From cfad0b8a529633c71dafc185135745dba2408682 Mon Sep 17 00:00:00 2001 From: Damian Schneider Date: Thu, 28 Aug 2025 18:08:31 +0200 Subject: [PATCH] bugfix to prevent "almost infinite" loops in palette blend (#4841) this fixes a very long loop when an overflow was happening in palette blending. - reset prevPaletteBlends to prevent overflow - add safety check in case overflow should still happen in another combination (or in future changes) --- wled00/FX_fcn.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 4fad8baa..40fc8907 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -282,6 +282,7 @@ void Segment::startTransition(uint16_t dur, bool segmentCopy) { _t->_oldSegment = new(std::nothrow) Segment(*this); // store/copy current segment settings _t->_start = millis(); // restart countdown _t->_dur = dur; + _t->_prevPaletteBlends = 0; if (_t->_oldSegment) { _t->_oldSegment->palette = _t->_palette; // restore original palette and colors (from start of transition) for (unsigned i = 0; i < NUM_COLORS; i++) _t->_oldSegment->colors[i] = _t->_colors[i]; @@ -368,6 +369,7 @@ void Segment::beginDraw(uint16_t prog) { // minimum blend time is 100ms maximum is 65535ms #ifndef WLED_SAVE_RAM unsigned noOfBlends = ((255U * prog) / 0xFFFFU) - _t->_prevPaletteBlends; + if(noOfBlends > 255) noOfBlends = 255; // safety check for (unsigned i = 0; i < noOfBlends; i++, _t->_prevPaletteBlends++) nblendPaletteTowardPalette(_t->_palT, Segment::_currentPalette, 48); Segment::_currentPalette = _t->_palT; // copy transitioning/temporary palette #else