diff --git a/src/core/hle/service/hid/controllers/capture_button.cpp b/src/core/hle/service/hid/controllers/capture_button.cpp index 8b486fcb51..7847c080e8 100644 --- a/src/core/hle/service/hid/controllers/capture_button.cpp +++ b/src/core/hle/service/hid/controllers/capture_button.cpp @@ -21,10 +21,11 @@ void CaptureButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { return; } + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/console_six_axis.cpp b/src/core/hle/service/hid/controllers/console_six_axis.cpp index 8eba2c292c..4b574c2e58 100644 --- a/src/core/hle/service/hid/controllers/console_six_axis.cpp +++ b/src/core/hle/service/hid/controllers/console_six_axis.cpp @@ -20,10 +20,11 @@ void ConsoleSixAxis::OnInit() {} void ConsoleSixAxis::OnRelease() {} void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index 2083ccfad9..afca7154c6 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp @@ -32,8 +32,10 @@ bool ControllerBase::IsControllerActivated() const { return is_activated; } -void ControllerBase::SetAppletResource(std::shared_ptr resource) { +void ControllerBase::SetAppletResource(std::shared_ptr resource, + std::recursive_mutex* resource_mutex) { applet_resource = resource; + shared_mutex = resource_mutex; } } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index 759ae0053a..b34b85ece8 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h @@ -42,11 +42,13 @@ public: bool IsControllerActivated() const; - void SetAppletResource(std::shared_ptr resource); + void SetAppletResource(std::shared_ptr resource, + std::recursive_mutex* resource_mutex); protected: bool is_activated{false}; std::shared_ptr applet_resource{nullptr}; + std::recursive_mutex* shared_mutex{nullptr}; Core::HID::HIDCore& hid_core; }; diff --git a/src/core/hle/service/hid/controllers/debug_mouse.cpp b/src/core/hle/service/hid/controllers/debug_mouse.cpp index f2f1a27f8e..ceeb78d36d 100644 --- a/src/core/hle/service/hid/controllers/debug_mouse.cpp +++ b/src/core/hle/service/hid/controllers/debug_mouse.cpp @@ -21,10 +21,11 @@ void DebugMouse::OnInit() {} void DebugMouse::OnRelease() {} void DebugMouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index 1811cf6206..dc83f90f3b 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp @@ -23,10 +23,11 @@ void DebugPad::OnInit() {} void DebugPad::OnRelease() {} void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/digitizer.cpp b/src/core/hle/service/hid/controllers/digitizer.cpp index c01580fd6d..d5514c9653 100644 --- a/src/core/hle/service/hid/controllers/digitizer.cpp +++ b/src/core/hle/service/hid/controllers/digitizer.cpp @@ -21,10 +21,11 @@ void Digitizer::OnUpdate(const Core::Timing::CoreTiming& core_timing) { return; } + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 6e686fe65c..c73da13ee1 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp @@ -28,10 +28,11 @@ Gesture::Gesture(Core::HID::HIDCore& hid_core_) : ControllerBase(hid_core_) { Gesture::~Gesture() = default; void Gesture::OnInit() { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } @@ -44,10 +45,11 @@ void Gesture::OnInit() { void Gesture::OnRelease() {} void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/home_button.cpp b/src/core/hle/service/hid/controllers/home_button.cpp index 71dd9bc08d..1397379f39 100644 --- a/src/core/hle/service/hid/controllers/home_button.cpp +++ b/src/core/hle/service/hid/controllers/home_button.cpp @@ -21,10 +21,11 @@ void HomeButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { return; } + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index c72b3e5ce1..c069bcbb25 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp @@ -22,10 +22,11 @@ void Keyboard::OnInit() {} void Keyboard::OnRelease() {} void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index 58deafbc56..3a8d1751b5 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp @@ -21,10 +21,11 @@ void Mouse::OnInit() {} void Mouse::OnRelease() {} void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index bf387e22d5..17cd0d7a07 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -128,7 +128,7 @@ void NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t c auto* data = applet_resource_holder.applet_resource->GetAruidDataByIndex(aruid_index); - if (data->flag.is_assigned) { + if (!data->flag.is_assigned) { continue; } diff --git a/src/core/hle/service/hid/controllers/six_axis.cpp b/src/core/hle/service/hid/controllers/six_axis.cpp index a5a67dea65..adab609111 100644 --- a/src/core/hle/service/hid/controllers/six_axis.cpp +++ b/src/core/hle/service/hid/controllers/six_axis.cpp @@ -27,10 +27,11 @@ void SixAxis::OnInit() {} void SixAxis::OnRelease() {} void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/sleep_button.cpp b/src/core/hle/service/hid/controllers/sleep_button.cpp index 978dc4c1f3..d44b1f4cc5 100644 --- a/src/core/hle/service/hid/controllers/sleep_button.cpp +++ b/src/core/hle/service/hid/controllers/sleep_button.cpp @@ -21,10 +21,11 @@ void SleepButton::OnUpdate(const Core::Timing::CoreTiming& core_timing) { return; } + std::scoped_lock shared_lock{*shared_mutex}; const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 291dc707e6..b585a5829d 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp @@ -30,7 +30,7 @@ void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/controllers/unique_pad.cpp b/src/core/hle/service/hid/controllers/unique_pad.cpp index 8230501a59..6c543031dc 100644 --- a/src/core/hle/service/hid/controllers/unique_pad.cpp +++ b/src/core/hle/service/hid/controllers/unique_pad.cpp @@ -24,7 +24,7 @@ void UniquePad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { const u64 aruid = applet_resource->GetActiveAruid(); auto* data = applet_resource->GetAruidData(aruid); - if (data == nullptr) { + if (data == nullptr || !data->flag.is_assigned) { return; } diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index ab49259acf..1f41e645dd 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -171,31 +171,31 @@ void ResourceManager::InitializeHidCommonSampler() { palma = std::make_shared(system.HIDCore(), service_context); six_axis = std::make_shared(system.HIDCore(), npad); - debug_pad->SetAppletResource(applet_resource); - digitizer->SetAppletResource(applet_resource); - keyboard->SetAppletResource(applet_resource); + debug_pad->SetAppletResource(applet_resource, &shared_mutex); + digitizer->SetAppletResource(applet_resource, &shared_mutex); + keyboard->SetAppletResource(applet_resource, &shared_mutex); npad->SetNpadExternals(applet_resource, &shared_mutex); - six_axis->SetAppletResource(applet_resource); - mouse->SetAppletResource(applet_resource); - debug_mouse->SetAppletResource(applet_resource); - home_button->SetAppletResource(applet_resource); - sleep_button->SetAppletResource(applet_resource); - capture_button->SetAppletResource(applet_resource); + six_axis->SetAppletResource(applet_resource, &shared_mutex); + mouse->SetAppletResource(applet_resource, &shared_mutex); + debug_mouse->SetAppletResource(applet_resource, &shared_mutex); + home_button->SetAppletResource(applet_resource, &shared_mutex); + sleep_button->SetAppletResource(applet_resource, &shared_mutex); + capture_button->SetAppletResource(applet_resource, &shared_mutex); } void ResourceManager::InitializeTouchScreenSampler() { gesture = std::make_shared(system.HIDCore()); touch_screen = std::make_shared(system.HIDCore()); - touch_screen->SetAppletResource(applet_resource); - gesture->SetAppletResource(applet_resource); + touch_screen->SetAppletResource(applet_resource, &shared_mutex); + gesture->SetAppletResource(applet_resource, &shared_mutex); } void ResourceManager::InitializeConsoleSixAxisSampler() { console_six_axis = std::make_shared(system.HIDCore()); seven_six_axis = std::make_shared(system); - console_six_axis->SetAppletResource(applet_resource); + console_six_axis->SetAppletResource(applet_resource, &shared_mutex); } void ResourceManager::InitializeAHidSampler() {