From 7d5ce994ab979cd96a21d26c6a71b16d4469144b Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Tue, 4 Oct 2022 13:50:01 +0200 Subject: [PATCH] WLED_DEBUG: fix for crash after LittleFS formating This fixes a "division by zero" in WLED_DEBUG code. LittleFS init seems to take some time, so we can arrive at "Loops/sec" with 0 loops executed --> crash. --- wled00/wled.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 47c0ed02..afe2095a 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -204,9 +204,11 @@ void WLED::loop() DEBUG_PRINT(F("State time: ")); DEBUG_PRINTLN(wifiStateChangedTime); DEBUG_PRINT(F("NTP last sync: ")); DEBUG_PRINTLN(ntpLastSyncTime); DEBUG_PRINT(F("Client IP: ")); DEBUG_PRINTLN(Network.localIP()); - DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 30); - DEBUG_PRINT(F("UM time[ms]: ")); DEBUG_PRINT(avgUsermodMillis/loops); DEBUG_PRINT("/");DEBUG_PRINTLN(maxUsermodMillis); - DEBUG_PRINT(F("Strip time[ms]: ")); DEBUG_PRINT(avgStripMillis/loops); DEBUG_PRINT("/"); DEBUG_PRINTLN(maxStripMillis); + if (loops > 0) { // avoid division by zero + DEBUG_PRINT(F("Loops/sec: ")); DEBUG_PRINTLN(loops / 30); + DEBUG_PRINT(F("UM time[ms]: ")); DEBUG_PRINT(avgUsermodMillis/loops); DEBUG_PRINT("/");DEBUG_PRINTLN(maxUsermodMillis); + DEBUG_PRINT(F("Strip time[ms]: ")); DEBUG_PRINT(avgStripMillis/loops); DEBUG_PRINT("/"); DEBUG_PRINTLN(maxStripMillis); + } strip.printSize(); loops = 0; maxUsermodMillis = 0;