robustness: prevent negative transitions

fix for a corner case that might lead to unexpected math overflow
This commit is contained in:
Frank
2025-01-17 21:36:51 +01:00
parent 2c0063dc5b
commit 0eec8e46c9

View File

@@ -194,7 +194,7 @@ void handleTransitions()
if (transitionActive && transitionDelayTemp > 0)
{
float tper = (millis() - transitionStartTime)/(float)transitionDelayTemp;
if (tper >= 1.0f)
if ((tper >= 1.0f) || (tper < 0.0f)) // WLEDMM also catch "<0" case, that may happen when millis() rolls over
{
strip.setTransitionMode(false);
// restore (global) transition time if not called from UDP notifier or single/temporary transition from JSON (also playlist)
@@ -207,7 +207,7 @@ void handleTransitions()
}
if (tper - tperLast < 0.004f) return;
tperLast = tper;
briT = briOld + ((bri - briOld) * tper);
briT = briOld + ((int(bri) - int(briOld)) * tper); // WLEDMM avoid undefined behaviour when briOld < bri
applyBri();
}