mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2024-12-20 22:16:49 +01:00
Fix shutting down HIDAPI device with multiple joysticks
Using Wii U GameCube USB adapter with multiple controllers attached and restarting SDL input in a game results in extra joysticks with NULL name. HIDAPI_CleanupDeviceDriver() shut down joysticks by iterating through device->num_joysticks but each HIDAPI_JoystickDisconnected() decreases device->num_joysticks and shifts joysticks array down. Resulting in only half of controllers being shutdown. It worked with only 1 controller attached though. Disconnect HIDAPI device joystick 0 until there are none left.
This commit is contained in:
parent
d000a592ab
commit
f0cee3edec
@ -484,20 +484,18 @@ HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device)
|
||||
static void
|
||||
HIDAPI_CleanupDeviceDriver(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!device->driver) {
|
||||
/* Already cleaned up */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Disconnect any joysticks */
|
||||
for (i = 0; i < device->num_joysticks; ++i) {
|
||||
SDL_Joystick *joystick = SDL_JoystickFromInstanceID(device->joysticks[i]);
|
||||
while (device->num_joysticks) {
|
||||
SDL_Joystick *joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
|
||||
if (joystick) {
|
||||
HIDAPI_JoystickClose(joystick);
|
||||
}
|
||||
HIDAPI_JoystickDisconnected(device, device->joysticks[i]);
|
||||
HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
|
||||
}
|
||||
|
||||
device->driver->FreeDevice(device);
|
||||
|
Loading…
Reference in New Issue
Block a user