summaryrefslogtreecommitdiffstats
path: root/src/input_common
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2020-09-03 17:07:57 +0200
committerMorph <39850852+Morph1984@users.noreply.github.com>2020-10-16 06:04:59 +0200
commit7b3f5845d28fdf245967b930452d392458fd8535 (patch)
tree7b627a0d7985ec42e90e6f4348f60c3094e31e0d /src/input_common
parentMerge pull request #4790 from lioncash/input-common (diff)
downloadyuzu-7b3f5845d28fdf245967b930452d392458fd8535.tar
yuzu-7b3f5845d28fdf245967b930452d392458fd8535.tar.gz
yuzu-7b3f5845d28fdf245967b930452d392458fd8535.tar.bz2
yuzu-7b3f5845d28fdf245967b930452d392458fd8535.tar.lz
yuzu-7b3f5845d28fdf245967b930452d392458fd8535.tar.xz
yuzu-7b3f5845d28fdf245967b930452d392458fd8535.tar.zst
yuzu-7b3f5845d28fdf245967b930452d392458fd8535.zip
Diffstat (limited to 'src/input_common')
-rw-r--r--src/input_common/sdl/sdl_impl.cpp28
1 files changed, 13 insertions, 15 deletions
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp
index 8c2cef35d..9c3035920 100644
--- a/src/input_common/sdl/sdl_impl.cpp
+++ b/src/input_common/sdl/sdl_impl.cpp
@@ -273,21 +273,19 @@ void SDLState::InitJoystick(int joystick_index) {
void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
const std::string guid = GetGUID(sdl_joystick);
- std::shared_ptr<SDLJoystick> found_joystick;
- {
- std::lock_guard lock{joystick_map_mutex};
- // This call to guid is safe since the joystick is guaranteed to be in the map
- const auto& joystick_guid_list = joystick_map[guid];
- const auto joystick_it = std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(),
- [&sdl_joystick](const auto& joystick) {
- return joystick->GetSDLJoystick() == sdl_joystick;
- });
- found_joystick = *joystick_it;
- }
-
- // Destruct SDL_Joystick outside the lock guard because SDL can internally call the
- // event callback which locks the mutex again.
- found_joystick->SetSDLJoystick(nullptr, nullptr);
+ std::lock_guard lock{joystick_map_mutex};
+ auto& joystick_guid_list = joystick_map[guid];
+ auto joystick_it = std::find_if(
+ joystick_guid_list.begin(), joystick_guid_list.end(),
+ [&sdl_joystick](auto& joystick) { return joystick->GetSDLJoystick() == sdl_joystick; });
+
+ if (joystick_it != joystick_guid_list.end()) {
+ (*joystick_it)->SetSDLJoystick(nullptr, nullptr);
+ joystick_guid_list.erase(joystick_it);
+ if (joystick_guid_list.empty()) {
+ joystick_map.erase(guid);
+ }
+ }
}
void SDLState::HandleGameControllerEvent(const SDL_Event& event) {