From 5d63a3d43528a9da9972b35a6444f3c8fd0ce752 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 9 Aug 2022 14:06:49 -0700 Subject: [PATCH] Re-enumerate devices if a read fails This allows combined Joy-Con devices to immediately separate if one of them is disconnected --- src/joystick/hidapi/SDL_hidapijoystick.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index fdeacc0f7e..10cdedd6ee 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -1003,7 +1003,10 @@ HIDAPI_UpdateDevices(void) if (device->driver) { if (SDL_TryLockMutex(device->dev_lock) == 0) { device->updating = SDL_TRUE; - device->driver->UpdateDevice(device); + if (!device->driver->UpdateDevice(device)) { + /* Try re-enumerating the device if it fails */ + SDL_HIDAPI_change_count = 0; + } device->updating = SDL_FALSE; SDL_UnlockMutex(device->dev_lock); }