From c10a87429d8a4175ae76b6e143948d33c3752013 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 31 Jul 2019 10:20:37 -0700 Subject: [PATCH] Make sure HIDAPI is initialized whenever we call HIDAPI_IsDevicePresent() --- src/joystick/hidapi/SDL_hidapijoystick.c | 5 +++++ src/joystick/linux/SDL_sysjoystick.c | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index c2d951961373b..9739742f9afd5 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -918,6 +918,11 @@ HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version) { SDL_HIDAPI_Device *device; + /* Make sure we're initialized, as this could be called from other drivers during startup */ + if (HIDAPI_JoystickInit() < 0) { + return SDL_FALSE; + } + /* Don't update the device list for devices we know aren't supported */ if (!HIDAPI_IsDeviceSupported(vendor_id, product_id, version)) { return SDL_FALSE; diff --git a/src/joystick/linux/SDL_sysjoystick.c b/src/joystick/linux/SDL_sysjoystick.c index 55b558ae52fca..ad830919677c1 100644 --- a/src/joystick/linux/SDL_sysjoystick.c +++ b/src/joystick/linux/SDL_sysjoystick.c @@ -120,8 +120,6 @@ IsJoystick(int fd, char *namebuf, const size_t namebuflen, SDL_JoystickGUID *gui } #ifdef SDL_JOYSTICK_HIDAPI - SDL_HIDAPI_JoystickDriver.Init(); - if (HIDAPI_IsDevicePresent(inpid.vendor, inpid.product, inpid.version)) { /* The HIDAPI driver is taking care of this device */ return 0;