Don't call hid_enumerate() if the HIDAPI drivers are all disabled
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index e420354..8e5c96c 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -96,6 +96,7 @@ static SDL_HIDAPI_DeviceDriver *SDL_HIDAPI_drivers[] = {
&SDL_HIDAPI_DriverXboxOne,
#endif
};
+static int SDL_HIDAPI_numdrivers = 0;
static SDL_HIDAPI_Device *SDL_HIDAPI_devices;
static int SDL_HIDAPI_numjoysticks = 0;
@@ -656,6 +657,14 @@ SDL_HIDAPIDriverHintChanged(void *userdata, const char *name, const char *oldVal
}
}
+ SDL_HIDAPI_numdrivers = 0;
+ for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
+ SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
+ if (driver->enabled) {
+ ++SDL_HIDAPI_numdrivers;
+ }
+ }
+
/* Update device list if driver availability changes */
while (device) {
if (device->driver) {
@@ -869,17 +878,19 @@ HIDAPI_UpdateDeviceList(void)
}
/* Enumerate the devices */
- devs = hid_enumerate(0, 0);
- if (devs) {
- for (info = devs; info; info = info->next) {
- device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
- if (device) {
- device->seen = SDL_TRUE;
- } else {
- HIDAPI_AddDevice(info);
+ if (SDL_HIDAPI_numdrivers > 0) {
+ devs = hid_enumerate(0, 0);
+ if (devs) {
+ for (info = devs; info; info = info->next) {
+ device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
+ if (device) {
+ device->seen = SDL_TRUE;
+ } else {
+ HIDAPI_AddDevice(info);
+ }
}
+ hid_free_enumeration(devs);
}
- hid_free_enumeration(devs);
}
/* Remove any devices that weren't seen */