Worked around bug with Sony PS Now PS3 controller where DirectInput polling will continue to return success after the controller is unplugged.

The code is now reliant on SDL_PrivateJoystickAdded() and SDL_PrivateJoystickRemoved() being called correctly when devices are added or removed on Windows
This commit is contained in:
Sam Lantinga 2018-08-09 16:03:50 -07:00
parent f35e97ba8a
commit 888bf1af69
17 changed files with 31 additions and 118 deletions

View file

@ -297,6 +297,7 @@ SDL_JoystickOpen(int device_index)
}
joystick->driver = driver;
joystick->instance_id = instance_id;
joystick->attached = SDL_TRUE;
if (driver->Open(joystick, device_index) < 0) {
SDL_free(joystick);
@ -545,7 +546,7 @@ SDL_JoystickGetAttached(SDL_Joystick * joystick)
return SDL_FALSE;
}
return joystick->driver->IsAttached(joystick);
return joystick->attached;
}
/*
@ -765,6 +766,8 @@ static void UpdateEventsForDeviceRemoval()
void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
{
SDL_Joystick *joystick;
#if !SDL_EVENTS_DISABLED
SDL_Event event;
@ -777,6 +780,15 @@ void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
UpdateEventsForDeviceRemoval();
#endif /* !SDL_EVENTS_DISABLED */
/* Mark this joystick as no longer attached */
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
if (joystick->instance_id == device_instance) {
joystick->attached = SDL_FALSE;
joystick->force_recentering = SDL_TRUE;
break;
}
}
}
int
@ -984,10 +996,12 @@ SDL_JoystickUpdate(void)
SDL_UnlockJoysticks();
for (joystick = SDL_joysticks; joystick; joystick = joystick->next) {
joystick->driver->Update(joystick);
if (joystick->attached) {
joystick->driver->Update(joystick);
if (joystick->delayed_guide_button) {
SDL_GameControllerHandleDelayedGuideButton(joystick);
if (joystick->delayed_guide_button) {
SDL_GameControllerHandleDelayedGuideButton(joystick);
}
}
if (joystick->force_recentering) {