Open JayFoxRox opened 4 years ago
@Ryzee119 briefly looked into this here: https://github.com/XboxDev/nxdk-sdl/pull/38#discussion_r611511381; so it looks like this might be broken / poor design in SDL:
I started messing with caching the device list locally and only sync to the 'real' list on
JoystickDetect
but SDL backend was calling things in a way I didnt expect. (I.eGetNumofJoysticks
was being called beforeJoystickDetect()
on hotplugs for example which messed with my inital plans.
Ive looked into this more and to do it properly you must only pump hotplug connection events (SDL_PrivateJoystickRemoved and SDL_PrivateJoystickAdded) in JoystickDetect()
. I was doing in the usb stack callbacks, instead these should only queue device removal/additions in the SDL backend.
I think JoystickDetect() should do this (in this order):
I havent got a working prototype yet, but some quick testing seems like this could work.
Looks like how the windows backend does it. https://github.com/XboxDev/nxdk-sdl/blob/nxdk/src/joystick/windows/SDL_windowsjoystick.c
I believe SDL expects no updates to return values of
SDL_JoystickNameForIndex
orSDL_NumJoysticks
inbetween SDL event pumping and / orSDL_JoystickUpdate
. Otherwise there might be race conditions.Imagine these steps in an app:
I don't think our driver respects this. We should check if / how other backends take care of this.
See #30 for another description of this / why I think this is violated.