From 6119e8fad2677e731e6105af6063cabe7be069f8 Mon Sep 17 00:00:00 2001 From: lizzie Date: Tue, 7 Jul 2026 19:52:22 +0200 Subject: [hid_core] fix LM2 crash due to callbacks not being removed properly (#4178) the function returned the key AFTER this one, which points to an invalid object basically its like "oh im returning the index AFTER Myself" off-by-1 error basically; now it returns OUR own key. Signed-off-by: lizzie Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4178 Reviewed-by: MaranBr Reviewed-by: CamilleLaVey --- src/input_common/input_engine.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/input_common/input_engine.cpp') diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index ccfe3444ae..21d257d088 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp @@ -4,6 +4,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/logging.h" +#include "common/assert.h" #include "input_common/input_engine.h" namespace InputCommon { @@ -463,8 +464,9 @@ const std::string& InputEngine::GetEngineName() const { int InputEngine::SetCallback(InputIdentifier input_identifier) { std::scoped_lock lock{mutex_callback}; + ++last_callback_key; callback_list.insert_or_assign(last_callback_key, std::move(input_identifier)); - return last_callback_key++; + return last_callback_key; } void InputEngine::SetMappingCallback(MappingCallback callback) { @@ -474,12 +476,9 @@ void InputEngine::SetMappingCallback(MappingCallback callback) { void InputEngine::DeleteCallback(int key) { std::scoped_lock lock{mutex_callback}; - const auto& iterator = callback_list.find(key); - if (iterator == callback_list.end()) { - LOG_ERROR(Input, "Tried to delete non-existent callback {}", key); - return; - } - callback_list.erase(iterator); + auto const it = callback_list.find(key); + ASSERT_MSG(it != callback_list.end(), "Tried to delete non-existent callback {}", key); + callback_list.erase(it); } } // namespace InputCommon -- cgit v1.2.3