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.
This commit is contained in:
Frank
2024-11-08 12:12:22 +01:00
parent 426805f674
commit b1194f597c

View File

@@ -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
}