Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDL Joystick information might change unexpectedly #31

Open
JayFoxRox opened this issue May 4, 2020 · 2 comments
Open

SDL Joystick information might change unexpectedly #31

JayFoxRox opened this issue May 4, 2020 · 2 comments

Comments

@JayFoxRox
Copy link
Member

JayFoxRox commented May 4, 2020

I believe SDL expects no updates to return values of SDL_JoystickNameForIndex or SDL_NumJoysticks inbetween SDL event pumping and / or SDL_JoystickUpdate. Otherwise there might be race conditions.

Imagine these steps in an app:

  1. A user asks SDL for the number of connected joystick devices
  2. User disconnects the USB device
  3. User takes device count from step 1. to loop over SDL joystick devices to ask for their name

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.

@JayFoxRox
Copy link
Member Author

JayFoxRox commented Apr 12, 2021

@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.e GetNumofJoysticks was being called before JoystickDetect() on hotplugs for example which messed with my inital plans.

@Ryzee119
Copy link

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):

  • Resync with usb backend
  • process queued device removal/connection events

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants