From b3853e1bdb60de0e82bf0a604cfd1a5273418c9e Mon Sep 17 00:00:00 2001 From: Extremesecrecy <10959169+extremesecrecy@users.noreply.github.com> Date: Thu, 24 Jul 2025 07:50:33 -0700 Subject: [PATCH] CPU Usage Dive by Zero Issue (Chrome Console Error Reported) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added explicit checks in “CpuUse::UpdateCpuUse” to avoid division by zero; CPU usage and overhead are forced to 0 when times are zero Validated audio driver CPU usage in “AudioHost::getJackStatus”, replacing non‑finite results with 0 --- src/AudioHost.cpp | 6 +++++- src/CpuUse.hpp | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/AudioHost.cpp b/src/AudioHost.cpp index 3cdb7cc..845302a 100644 --- a/src/AudioHost.cpp +++ b/src/AudioHost.cpp @@ -2119,7 +2119,11 @@ public: if (this->audioDriver != nullptr) { - result.cpuUsage_ = audioDriver->CpuUse(); + result.cpuUsage_ = audioDriver->CpuUse(); + if (!std::isfinite(result.cpuUsage_)) + { + result.cpuUsage_ = 0.0f; + } } GetCpuFrequency(&result.cpuFreqMin_, &result.cpuFreqMax_); result.hasCpuGovernor_ = HasCpuGovernor(); diff --git a/src/CpuUse.hpp b/src/CpuUse.hpp index e2dedac..d5b96d2 100644 --- a/src/CpuUse.hpp +++ b/src/CpuUse.hpp @@ -140,14 +140,19 @@ namespace pipedal overheadTime = readTime; } - SampleT totalTime = writeTime+ readTime + processingTime; - SampleT maxTime = waitTime+processingTime; - + SampleT totalTime = writeTime + readTime + processingTime; + SampleT maxTime = waitTime + processingTime; - float result = 100.0f*(processingTime)/(maxTime); - float overhead = 100.0F*(overheadTime*2)/totalTime; + float result = 0.0f; + float overhead = 0.0f; + if (maxTime != 0 && totalTime != 0) { - std::lock_guard lock { sync}; + result = 100.0f * (processingTime) / (maxTime); + overhead = 100.0f * (overheadTime * 2) / totalTime; + } + + { + std::lock_guard lock{sync}; currentCpuUse = result; currentOverhead = overhead; }