diff options
author | Mark Kriegsman <1334634+kriegsman@users.noreply.github.com> | 2020-01-30 03:55:42 +0300 |
---|---|---|
committer | Mark Kriegsman <1334634+kriegsman@users.noreply.github.com> | 2020-01-30 03:55:42 +0300 |
commit | 5608ecf7771274a9724d72bc848c33e0026dad7b (patch) | |
tree | d7870e2a04d3ee79592eb6ea3d3ae2ef84559afc | |
parent | 42441aaa2448c02480846ba6015180347ac61257 (diff) |
Prevent divide-by-zero, fixes #881. Thanks to @limpens and @andjoeg for help with this.
-rw-r--r-- | FastLED.cpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/FastLED.cpp b/FastLED.cpp index 94f23021..bfcb73c4 100644 --- a/FastLED.cpp +++ b/FastLED.cpp @@ -208,9 +208,12 @@ void CFastLED::countFPS(int nFrames) { static uint32_t lastframe = 0; // millis(); if(br++ >= nFrames) { - uint32_t now = millis(); - now -= lastframe; - m_nFPS = (br * 1000) / now; + uint32_t now = millis(); + now -= lastframe; + if( now == 0 ) { + now = 1; // prevent division by zero below + } + m_nFPS = (br * 1000) / now; br = 0; lastframe = millis(); } |