Skip to content
Snippets Groups Projects
Commit 7b3f5845 authored by Morph's avatar Morph
Browse files

sdl_impl: Erase the SDLJoystick entry after removing a controller

Previously, disconnecting a controller still leaves a null SDLJoystick entry within the vector of SDLJoysticks mapped by GUID.
When a DirectInput device of the same GUID is reconnected, it adds that device to a new port causing non-detectable input.
Furthermore, opening the "Configure" menu would cause yuzu to crash since it first tries to resolve the name of a null SDLJoystick entry that was not removed.
Resolve this by properly erasing the SDLJoystick entry from the vector.
parent 64f967fd
No related branches found
No related tags found
No related merge requests found
...@@ -273,21 +273,19 @@ void SDLState::InitJoystick(int joystick_index) { ...@@ -273,21 +273,19 @@ void SDLState::InitJoystick(int joystick_index) {
void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) { void SDLState::CloseJoystick(SDL_Joystick* sdl_joystick) {
const std::string guid = GetGUID(sdl_joystick); const std::string guid = GetGUID(sdl_joystick);
std::shared_ptr<SDLJoystick> found_joystick; std::lock_guard lock{joystick_map_mutex};
{ auto& joystick_guid_list = joystick_map[guid];
std::lock_guard lock{joystick_map_mutex}; auto joystick_it = std::find_if(
// This call to guid is safe since the joystick is guaranteed to be in the map joystick_guid_list.begin(), joystick_guid_list.end(),
const auto& joystick_guid_list = joystick_map[guid]; [&sdl_joystick](auto& joystick) { return joystick->GetSDLJoystick() == sdl_joystick; });
const auto joystick_it = std::find_if(joystick_guid_list.begin(), joystick_guid_list.end(),
[&sdl_joystick](const auto& joystick) { if (joystick_it != joystick_guid_list.end()) {
return joystick->GetSDLJoystick() == sdl_joystick; (*joystick_it)->SetSDLJoystick(nullptr, nullptr);
}); joystick_guid_list.erase(joystick_it);
found_joystick = *joystick_it; if (joystick_guid_list.empty()) {
} joystick_map.erase(guid);
}
// 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);
} }
void SDLState::HandleGameControllerEvent(const SDL_Event& event) { void SDLState::HandleGameControllerEvent(const SDL_Event& event) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment