From 3b3ae4d14df68e09ba0dab0f657da8512215b02e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Mar 2020 15:06:47 -0800 Subject: [PATCH] Possible fix for bug 5010 - SDL_Init with SDL_INIT_JOYSTICK hangs for 10 seconds when playing audio from another application Jake Breen When I run SDL_INIT with SDL_INIT_JOYSTICK it stalls for about 10 seconds (last report was 10,615ms), but only if I'm currently playing audio. (Like in Spotify for example.) querying something related to device access (last dll loaded) 'BabbysFirst64.exe' (Win32): Loaded 'C:\Windows\SysWOW64\deviceaccess.dll'. I use a USB DAC because my mobo's audio out is pretty not great. And I've noticed unplugging it seems to solve the issue. I haven't noticed any other issues that are caused by my DAC. My DAC is the Sound BlasterX G1 https://us.creative.com/p/gaming-headsets/sound-blasterx-g1 Vid = 041E PID = 3249 My system specs: - Windows 10 Pro - Ryzen 2700x - 16GB Ram - Nvidia 2070 RTX Additional USB devices plugged in: - Valve Index - Xbox One Elite Controller --- src/joystick/SDL_joystick.c | 5 ++++- src/joystick/hidapi/SDL_hidapijoystick.c | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c index 406d148e332ce..5f74ec4d6ac6b 100644 --- a/src/joystick/SDL_joystick.c +++ b/src/joystick/SDL_joystick.c @@ -1687,10 +1687,13 @@ static SDL_bool SDL_IsPS4RemapperRunning(void) SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid) { - /* This list is taken from: + /* This list (except for marked entries at the top) is taken from: https://raw.githubusercontent.com/denilsonsa/udev-joystick-blacklist/master/generate_rules.py */ static Uint32 joystick_blacklist[] = { + /* Sound BlasterX G1 */ + MAKE_VIDPID(0x041E, 0x3249), + /* Microsoft Microsoft Wireless Optical DesktopĀ® 2.10 */ /* Microsoft Wireless Desktop - Comfort Edition */ MAKE_VIDPID(0x045e, 0x009d), diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index ada3088a73bf4..579d0965c2166 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -413,7 +413,7 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device) const Uint16 USAGE_GAMEPAD = 0x0005; const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008; int i; - SDL_GameControllerType type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol); + SDL_GameControllerType type; if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) { return NULL; @@ -426,6 +426,7 @@ HIDAPI_GetDeviceDriver(SDL_HIDAPI_Device *device) return NULL; } + type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol); for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) { SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i]; if (driver->enabled && driver->IsSupportedDevice(device->name, type, device->vendor_id, device->product_id, device->version, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol)) {