diff options
| author | lizzie <lizzie@eden-emu.dev> | 2026-07-07 19:52:22 +0200 |
|---|---|---|
| committer | crueter <crueter@eden-emu.dev> | 2026-07-07 19:52:22 +0200 |
| commit | 6119e8fad2677e731e6105af6063cabe7be069f8 (patch) | |
| tree | 157ca48f4940a560096f3842f9b49d0365f31a54 /src/hid_core/frontend/emulated_console.cpp | |
| parent | bfc0e60333310c252e168b354ba3eb0802510864 (diff) | |
[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 <lizzie@eden-emu.dev>
Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4178
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: CamilleLaVey <camillelavey99@gmail.com>
Diffstat (limited to 'src/hid_core/frontend/emulated_console.cpp')
| -rw-r--r-- | src/hid_core/frontend/emulated_console.cpp | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/hid_core/frontend/emulated_console.cpp b/src/hid_core/frontend/emulated_console.cpp index 114c22fb74..3807b9e182 100644 --- a/src/hid_core/frontend/emulated_console.cpp +++ b/src/hid_core/frontend/emulated_console.cpp @@ -1,7 +1,11 @@ +// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later #include "common/settings.h" +#include "common/assert.h" #include "hid_core/frontend/emulated_console.h" #include "hid_core/frontend/input_converter.h" @@ -308,17 +312,15 @@ void EmulatedConsole::TriggerOnChange(ConsoleTriggerType type) { int EmulatedConsole::SetCallback(ConsoleUpdateCallback update_callback) { std::scoped_lock lock{callback_mutex}; + ++last_callback_key; callback_list.insert_or_assign(last_callback_key, std::move(update_callback)); - return last_callback_key++; + return last_callback_key; } void EmulatedConsole::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); - 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 Core::HID |
