mirror of
				https://git.suyu.dev/suyu/suyu.git
				synced 2025-11-04 12:34:39 +08:00 
			
		
		
		
	Merge pull request #4627 from Morph1984/fix-dinput-controller-disconnect
sdl_impl: Erase the SDLJoystick entry after removing a controller
This commit is contained in:
		
						commit
						e03dc4d569
					
				@ -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) {
 | 
					 | 
				
			||||||
                                                  return joystick->GetSDLJoystick() == sdl_joystick;
 | 
					 | 
				
			||||||
                                              });
 | 
					 | 
				
			||||||
        found_joystick = *joystick_it;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Destruct SDL_Joystick outside the lock guard because SDL can internally call the
 | 
					    if (joystick_it != joystick_guid_list.end()) {
 | 
				
			||||||
    // event callback which locks the mutex again.
 | 
					        (*joystick_it)->SetSDLJoystick(nullptr, nullptr);
 | 
				
			||||||
    found_joystick->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) {
 | 
					void SDLState::HandleGameControllerEvent(const SDL_Event& event) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user