From 64a1cc1d7ca07a9cc89595bda9fc0acfcdb857e3 Mon Sep 17 00:00:00 2001 From: german77 Date: Fri, 1 Apr 2022 22:26:44 -0600 Subject: [PATCH] core: hid: Remove service callbacks on game close --- src/core/hid/emulated_controller.cpp | 8 ++++++++ src/core/hid/emulated_controller.h | 3 +++ src/core/hid/hid_core.cpp | 13 +++++++++++++ src/core/hid/hid_core.h | 3 +++ src/yuzu/main.cpp | 3 ++- 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 7e05666d6b..205648bd39 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -1207,4 +1207,12 @@ void EmulatedController::DeleteCallback(int key) { } callback_list.erase(iterator); } + +void EmulatedController::RemoveServiceCallbacks() { + std::lock_guard lock{mutex}; + const auto count = std::erase_if( + callback_list, [](const auto& callback) { return callback.second.is_npad_service; }); + LOG_DEBUG(Input, "Elements deleted {}", count); +} + } // namespace Core::HID diff --git a/src/core/hid/emulated_controller.h b/src/core/hid/emulated_controller.h index aa52f9572f..193be04f3c 100644 --- a/src/core/hid/emulated_controller.h +++ b/src/core/hid/emulated_controller.h @@ -335,6 +335,9 @@ public: */ void DeleteCallback(int key); + /// Removes all callbacks created from npad services + void RemoveServiceCallbacks(); + private: /// creates input devices from params void LoadDevices(); diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp index a1c3bbb579..fe9d7d3f4c 100644 --- a/src/core/hid/hid_core.cpp +++ b/src/core/hid/hid_core.cpp @@ -211,4 +211,17 @@ void HIDCore::UnloadInputDevices() { devices->UnloadInput(); } +void HIDCore::RemoveServiceCallbacks() { + player_1->RemoveServiceCallbacks(); + player_2->RemoveServiceCallbacks(); + player_3->RemoveServiceCallbacks(); + player_4->RemoveServiceCallbacks(); + player_5->RemoveServiceCallbacks(); + player_6->RemoveServiceCallbacks(); + player_7->RemoveServiceCallbacks(); + player_8->RemoveServiceCallbacks(); + other->RemoveServiceCallbacks(); + handheld->RemoveServiceCallbacks(); +} + } // namespace Core::HID diff --git a/src/core/hid/hid_core.h b/src/core/hid/hid_core.h index 717f605e7b..02f423c2ca 100644 --- a/src/core/hid/hid_core.h +++ b/src/core/hid/hid_core.h @@ -61,6 +61,9 @@ public: /// Removes all callbacks from input common void UnloadInputDevices(); + /// Removes all callbacks from npad services + void RemoveServiceCallbacks(); + /// Number of emulated controllers static constexpr std::size_t available_controllers{10}; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 3b7058a2bf..2031f77070 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1533,8 +1533,9 @@ void GMainWindow::ShutdownGame() { input_subsystem->GetTas()->Stop(); OnTasStateChanged(); - // Enable all controllers + // Enable all controllers types and remove all service callbacks system->HIDCore().SetSupportedStyleTag({Core::HID::NpadStyleSet::All}); + system->HIDCore().RemoveServiceCallbacks(); render_window->removeEventFilter(render_window); render_window->setAttribute(Qt::WA_Hover, false);