Clean up stale detached gamepads before hotplug reattach
This commit is contained in:
parent
e88be5dce2
commit
ca41cf32cc
2 changed files with 23 additions and 0 deletions
|
|
@ -63,6 +63,25 @@ SdlInputHandler::findStateForGamepad(SDL_JoystickID id)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void SdlInputHandler::cleanupDetachedGamepads()
|
||||
{
|
||||
for (int i = 0; i < MAX_GAMEPADS; i++) {
|
||||
if (m_GamepadState[i].controller == nullptr ||
|
||||
SDL_GameControllerGetAttached(m_GamepadState[i].controller)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
|
||||
"Found detached gamepad in slot %d without removal event; cleaning up",
|
||||
i);
|
||||
|
||||
SDL_ControllerDeviceEvent controllerEvent = {};
|
||||
controllerEvent.type = SDL_CONTROLLERDEVICEREMOVED;
|
||||
controllerEvent.which = m_GamepadState[i].jsId;
|
||||
handleControllerDeviceEvent(&controllerEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void SdlInputHandler::sendGamepadState(GamepadState* state)
|
||||
{
|
||||
SDL_assert(m_GamepadMask == 0x1 || m_MultiController);
|
||||
|
|
@ -582,6 +601,8 @@ void SdlInputHandler::handleControllerDeviceEvent(SDL_ControllerDeviceEvent* eve
|
|||
GamepadState* state;
|
||||
|
||||
if (event->type == SDL_CONTROLLERDEVICEADDED) {
|
||||
cleanupDetachedGamepads();
|
||||
|
||||
int i;
|
||||
const char* name;
|
||||
SDL_GameController* controller;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue