mirror of
https://github.com/Ryujinx/SDL.git
synced 2024-12-23 18:55:32 +00:00
Sometimes the HID open doesn't succeed immediately after being notified about the device
Tested on Steam Link hardware with the Nintendo Switch Pro controller, which will occasionally take 2 attempts to open.
This commit is contained in:
parent
27ee8c8e14
commit
b75d318776
|
@ -368,6 +368,8 @@ HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, SDL_bool *removed)
|
||||||
*
|
*
|
||||||
* See https://github.com/libsdl-org/SDL/issues/6347 for details
|
* See https://github.com/libsdl-org/SDL/issues/6347 for details
|
||||||
*/
|
*/
|
||||||
|
const int MAX_ATTEMPTS = 3;
|
||||||
|
int attempt;
|
||||||
int lock_count = 0;
|
int lock_count = 0;
|
||||||
SDL_HIDAPI_Device *curr;
|
SDL_HIDAPI_Device *curr;
|
||||||
SDL_hid_device *dev;
|
SDL_hid_device *dev;
|
||||||
|
@ -378,7 +380,14 @@ HIDAPI_SetupDeviceDriver(SDL_HIDAPI_Device *device, SDL_bool *removed)
|
||||||
++lock_count;
|
++lock_count;
|
||||||
SDL_UnlockJoysticks();
|
SDL_UnlockJoysticks();
|
||||||
}
|
}
|
||||||
dev = SDL_hid_open_path(path, 0);
|
for (attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
|
||||||
|
dev = SDL_hid_open_path(path, 0);
|
||||||
|
if (dev != NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* Wait a bit and try again */
|
||||||
|
SDL_Delay(30);
|
||||||
|
}
|
||||||
while (lock_count > 0) {
|
while (lock_count > 0) {
|
||||||
--lock_count;
|
--lock_count;
|
||||||
SDL_LockJoysticks();
|
SDL_LockJoysticks();
|
||||||
|
|
Loading…
Reference in a new issue