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: safer code to resolve intermittent controller crashes related to disconnections #2755

Merged
merged 3 commits into from
Jun 23, 2023

Conversation

xTVaser
Copy link
Member

@xTVaser xTVaser commented Jun 19, 2023

Related to #2752

I had to try really hard to reproduce this (constantly unplugging and plugging in my controller). But this seems to happen for a variety of reasons (i got an DirectX error on the SDL_GameControllerOpen call one time), now any issue in the original initialization will result in the controller being skipped and picked up on the next reconnect (hopefully).

This may introduce a bug where controllers that legitimately have no name are ignored. To work around this, a call to SDL_GameControllerGetAttached may be needed to differentiate between a bad device handle and a nameless controller.
Nope, controllers in this state return true for being "attached and valid":
image

Also I was able to reproduce the LED crash, hopefully checking the handle is sufficient to stave that off, but it might be a bug internally in SDL (because it should just be returning -1, not crashing somewhere).

@xTVaser xTVaser marked this pull request as draft June 19, 2023 21:46
@xTVaser
Copy link
Member Author

xTVaser commented Jun 22, 2023

Isolated code that touches SDL directly which is called from the EE. After fixing the errors in the initialization of a GameController:

  • Noticed that anytime SDL_GameControllerName was null the guid was also empty
  • This let me revert the change to SDL_GameControllerName so that if NULL is returned (which is valid, aka no string) it will default to "" again.

I was still getting crashes related to the LED though. My theory is that while the EE thread is hammering these SDL functions every frame to do things like update the LED or the vibration -- the other thread is trying to handle the event that the controller has disconnected and tear it down. By isolating that code to run after all SDL events have been processed for that frame, this should make things more consistent. In my testing I unplugged/plugged in my controller for a few minutes straight with no crashes

@xTVaser xTVaser marked this pull request as ready for review June 22, 2023 23:54
@xTVaser xTVaser changed the title sdl: safer code around intermittent controller disconnects sdl: safer code to resolve intermittent controller disconnects + crashes Jun 23, 2023
@xTVaser xTVaser changed the title sdl: safer code to resolve intermittent controller disconnects + crashes sdl: safer code to resolve intermittent controller crashes related to disconnections Jun 23, 2023
@xTVaser xTVaser merged commit 679986e into open-goal:master Jun 23, 2023
8 checks passed
@xTVaser xTVaser deleted the v/input-disconnects branch June 23, 2023 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant