From b1194f597c4111fe967ded1bb2a228c098c55bda Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:12:22 +0100 Subject: [PATCH] fix for a potential endless loop in palette blending this bug is hard to trigger - when a palette transition is in progress and the main loop gets delayed (wifi connect, saving large preset files) then a calculation in setCurrentPalette() could overflow leading to an infinite loop. --- wled00/FX_fcn.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index a735bdc4..d2602218 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -487,7 +487,7 @@ void Segment::setCurrentPalette() { // there are about 255 blend passes of 48 "blends" to completely blend two palettes (in _dur time) // minimum blend time is 100ms maximum is 65535ms unsigned long timeMS = millis() - _t->_start; - uint16_t noOfBlends = (255U * timeMS / _t->_dur) - _t->_prevPaletteBlends; + uint16_t noOfBlends = min(64UL, (255U * timeMS / _t->_dur) - _t->_prevPaletteBlends); // WLEDMM limit to 64 blends at once, prevent rollover for (unsigned i = 0; i < noOfBlends; i++, _t->_prevPaletteBlends++) nblendPaletteTowardPalette(_t->_palT, _currentPalette, 48); _currentPalette = _t->_palT; // copy transitioning/temporary palette }