Skip to content

Commit cfad0b8

Browse files
authored
bugfix to prevent "almost infinite" loops in palette blend (wled#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)
1 parent f15c1fb commit cfad0b8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

wled00/FX_fcn.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ void Segment::startTransition(uint16_t dur, bool segmentCopy) {
282282
_t->_oldSegment = new(std::nothrow) Segment(*this); // store/copy current segment settings
283283
_t->_start = millis(); // restart countdown
284284
_t->_dur = dur;
285+
_t->_prevPaletteBlends = 0;
285286
if (_t->_oldSegment) {
286287
_t->_oldSegment->palette = _t->_palette; // restore original palette and colors (from start of transition)
287288
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) {
368369
// minimum blend time is 100ms maximum is 65535ms
369370
#ifndef WLED_SAVE_RAM
370371
unsigned noOfBlends = ((255U * prog) / 0xFFFFU) - _t->_prevPaletteBlends;
372+
if(noOfBlends > 255) noOfBlends = 255; // safety check
371373
for (unsigned i = 0; i < noOfBlends; i++, _t->_prevPaletteBlends++) nblendPaletteTowardPalette(_t->_palT, Segment::_currentPalette, 48);
372374
Segment::_currentPalette = _t->_palT; // copy transitioning/temporary palette
373375
#else

0 commit comments

Comments
 (0)