From 62c060da4521f7b87ee19f2bddf15eaaa0e5e82a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Jan 2026 14:57:43 +0000 Subject: [PATCH] Remove std::thread wrappers in display callbacks to fix thread safety Remove detached threads that were calling SetChatMessage from download/upgrade progress callbacks. The DisplayLockGuard mutex already provides thread safety, so we can call display methods directly from the callback thread without spawning additional threads, which were causing race conditions. Co-authored-by: 78 <4488133+78@users.noreply.github.com> --- main/application.cc | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/main/application.cc b/main/application.cc index 06ea456c..a920378b 100644 --- a/main/application.cc +++ b/main/application.cc @@ -369,11 +369,9 @@ void Application::CheckAssetsVersion() { display->SetChatMessage("system", Lang::Strings::PLEASE_WAIT); bool success = assets.Download(download_url, [display](int progress, size_t speed) -> void { - std::thread([display, progress, speed]() { - char buffer[32]; - snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024); - display->SetChatMessage("system", buffer); - }).detach(); + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024); + display->SetChatMessage("system", buffer); }); board.SetPowerSaveLevel(PowerSaveLevel::LOW_POWER); @@ -922,11 +920,9 @@ bool Application::UpgradeFirmware(const std::string& url, const std::string& ver vTaskDelay(pdMS_TO_TICKS(1000)); bool upgrade_success = Ota::Upgrade(upgrade_url, [display](int progress, size_t speed) { - std::thread([display, progress, speed]() { - char buffer[32]; - snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024); - display->SetChatMessage("system", buffer); - }).detach(); + char buffer[32]; + snprintf(buffer, sizeof(buffer), "%d%% %uKB/s", progress, speed / 1024); + display->SetChatMessage("system", buffer); }); if (!upgrade_success) {