From 3de27e989abc9c5b55539c688efce2cea8ecd84c Mon Sep 17 00:00:00 2001 From: Collecting Date: Thu, 8 Jan 2026 07:14:35 +0000 Subject: [PATCH] fix(ui): Improper Overlay Shutdown & Zombie Processes Signed-off-by: Collecting --- src/hid_core/frontend/emulated_controller.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 1a150bb91..cc5ae69cc 100644 --- a/src/hid_core/frontend/emulated_controller.cpp +++ b/src/hid_core/frontend/emulated_controller.cpp @@ -1998,13 +1998,23 @@ int EmulatedController::SetCallback(ControllerUpdateCallback update_callback) { } void EmulatedController::DeleteCallback(int key) { - std::scoped_lock lock{callback_mutex}; - const auto& iterator = callback_list.find(key); - if (iterator == callback_list.end()) { - LOG_ERROR(Input, "Tried to delete non-existent callback {}", key); + // 1. If the key is invalid, get out immediately. + if (key < 0) { return; } - callback_list.erase(iterator); + + std::scoped_lock lock{callback_mutex}; + + // 2. Check if the list itself is valid. + if (callback_list.empty()) { + return; + } + + // 3. Use a safe find. Do NOT use the result if it's the end of the map. + auto it = callback_list.find(key); + if (it != callback_list.end()) { + callback_list.erase(it); + } } void EmulatedController::StatusUpdate() {