From 3e7e9e349a8ca14d27805851b005c142753a6138 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Thu, 3 Sep 2026 21:50:45 +0200 Subject: [PATCH] fix(sim): skip blocking pre-shutdown buzzer wait in SIM_PLATFORM builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UITask::shutdown() busy-waits on buzzer.isPlaying() for up to 2.5s before powering off. On real hardware that's a real (if crude) wait; in the Emscripten sim it's a synchronous block on the browser's single JS/wasm thread, which freezes the whole page for the duration -- reported as the site "zacinanie siÄ™" (stuttering) whenever hibernate/shutdown triggers. Guards it with #ifdef SIM_PLATFORM, mirroring the identical pattern already used a few lines below for the low-battery pre-shutdown pause. Verified empirically (not just by reading the diff): measured real requestAnimationFrame throughput on meshcore-solo-site while triggering hibernate for real (Home -> Shutdown page -> Enter). Before: 135 frames in 3.5s (607ms max stall). After: 633 frames in the same window (110ms max) -- confirmed with a real stash/rebuild before-after control. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_018iubftDmKNWmkNnhJRz8UH --- examples/companion_radio/ui-new/UITask.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index fc0af20f..d3866959 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -2023,9 +2023,17 @@ void UITask::shutdown(bool restart){ while a non-blocking buzzer.loop() plays out in UITask::loop() */ buzzer.shutdown(); +#ifdef SIM_PLATFORM + // The sim runs single-threaded on the browser's main JS thread (no real + // hardware to actually shut down) -- up to 2.5s of a real, synchronous + // busy-wait here blocks that thread and freezes the whole page for the + // duration, same class of issue as the low-battery pre-shutdown pause + // skipped below. Skip the wait entirely in the sim. +#else uint32_t buzzer_timer = millis(); // fail-safe shutdown while (buzzer.isPlaying() && (millis() - buzzer_timer) < 2500) buzzer.loop(); +#endif #endif // PIN_BUZZER