Possible fix for bug 5010 - SDL_Init with SDL_INIT_JOYSTICK hangs for 10 seconds when playing audio from another application
authorSam Lantinga <slouken@libsdl.org>
Mon, 02 Mar 2020 15:06:47 -0800
changeset 135783e9f11265172
parent 13577 d28975f16368
child 13579 5669d9183f75
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
src/joystick/hidapi/SDL_hidapijoystick.c
     1.1 --- a/src/joystick/SDL_joystick.c	Mon Mar 02 14:55:40 2020 -0800
     1.2 +++ b/src/joystick/SDL_joystick.c	Mon Mar 02 15:06:47 2020 -0800
     1.3 @@ -1687,10 +1687,13 @@
     1.4  
     1.5  SDL_bool SDL_ShouldIgnoreJoystick(const char *name, SDL_JoystickGUID guid)
     1.6  {
     1.7 -    /* This list is taken from:
     1.8 +    /* This list (except for marked entries at the top) is taken from:
     1.9         https://raw.githubusercontent.com/denilsonsa/udev-joystick-blacklist/master/generate_rules.py
    1.10       */
    1.11      static Uint32 joystick_blacklist[] = {
    1.12 +        /* Sound BlasterX G1 */
    1.13 +        MAKE_VIDPID(0x041E, 0x3249),
    1.14 +
    1.15          /* Microsoft Microsoft Wireless Optical DesktopĀ® 2.10 */
    1.16          /* Microsoft Wireless Desktop - Comfort Edition */
    1.17          MAKE_VIDPID(0x045e, 0x009d),
     2.1 --- a/src/joystick/hidapi/SDL_hidapijoystick.c	Mon Mar 02 14:55:40 2020 -0800
     2.2 +++ b/src/joystick/hidapi/SDL_hidapijoystick.c	Mon Mar 02 15:06:47 2020 -0800
     2.3 @@ -413,7 +413,7 @@
     2.4      const Uint16 USAGE_GAMEPAD = 0x0005;
     2.5      const Uint16 USAGE_MULTIAXISCONTROLLER = 0x0008;
     2.6      int i;
     2.7 -    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);
     2.8 +    SDL_GameControllerType type;
     2.9  
    2.10      if (SDL_ShouldIgnoreJoystick(device->name, device->guid)) {
    2.11          return NULL;
    2.12 @@ -426,6 +426,7 @@
    2.13          return NULL;
    2.14      }
    2.15  
    2.16 +    type = SDL_GetJoystickGameControllerType(device->name, device->vendor_id, device->product_id, device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol);
    2.17      for (i = 0; i < SDL_arraysize(SDL_HIDAPI_drivers); ++i) {
    2.18          SDL_HIDAPI_DeviceDriver *driver = SDL_HIDAPI_drivers[i];
    2.19          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)) {