Commit adb53d0b1fb87ac0522d6ff6d06f8a1b9a291fb6

Sam Lantinga 2020-01-26T10:32:39

Fixed disabling the Xbox 360 wireless HIDAPI driver

diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 9f22a38..58dd653 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -504,7 +504,7 @@ static void SDLCALL
 SDL_HIDAPIDriverHintChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
 {
     int i;
-    SDL_HIDAPI_Device *device = SDL_HIDAPI_devices;
+    SDL_HIDAPI_Device *device;
     SDL_bool enabled = SDL_GetStringBoolean(hint, SDL_TRUE);
 
     if (SDL_strcmp(name, SDL_HINT_JOYSTICK_HIDAPI) == 0) {
@@ -517,7 +517,6 @@ SDL_HIDAPIDriverHintChanged(void *userdata, const char *name, const char *oldVal
             SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
             if (SDL_strcmp(name, driver->hint) == 0) {
                 driver->enabled = enabled;
-                break;
             }
         }
     }
@@ -533,12 +532,11 @@ SDL_HIDAPIDriverHintChanged(void *userdata, const char *name, const char *oldVal
     /* Update device list if driver availability changes */
     SDL_LockJoysticks();
 
-    while (device) {
+    for (device = SDL_HIDAPI_devices; device; device = device->next) {
         if (device->driver && !device->driver->enabled) {
             HIDAPI_CleanupDeviceDriver(device);
         }
         HIDAPI_SetupDeviceDriver(device);
-        device = device->next;
     }
 
     SDL_UnlockJoysticks();
@@ -741,7 +739,7 @@ HIDAPI_AddDevice(struct hid_device_info *info)
     HIDAPI_SetupDeviceDriver(device);
 
 #ifdef DEBUG_HIDAPI
-    SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, interface_class %d, interface_subclass %d, interface_protocol %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE");
+    SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, interface %d, interface_class %d, interface_subclass %d, interface_protocol %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s (%s)\n", device->name, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE", device->driver && device->driver->enabled ? "ENABLED" : "DISABLED");
 #endif
 }