Skip to content

Checks if Xinput2 is loaded before trying to call Xinput2 functions #13148

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

Merged
merged 1 commit into from
Jun 1, 2025

Conversation

MasonRemaley
Copy link
Contributor

Fixes a crash if Xinput2 fails to load.

Description

If SDL_VIDEO_DRIVER_X11_XINPUT2 and SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 are defined, SDL will try to load Xinput2 at runtime. If this succeeds, everything works as expected.

However, if SDL fails to find Xinput2, it will attempt to call some Xinput2 functions anyway. Right now, they're guarded on the feature being enabled not on the library being loaded. Since the library failed to load, the functions will be null, so calling them typically leads to a crash.

This PR checks whether or not XInput2 was successfully initialized before calling these functions. It's possible that I didn't catch every instance of this issue--the calls in SDL_x11pen.c were easy to find as one of them happens at init time.

(I'm a first time contributor--if there's a better/more robust way to fix this feel free to let me know! I'm not sure how the equivalent logic is handled for the other runtime optional dependencies.)

Existing Issue(s)

none

@MasonRemaley MasonRemaley changed the title Checks if Xinput2 is loaded before trying to call xinput2 functions Checks if Xinput2 is loaded before trying to call Xinput2 functions May 29, 2025
@icculus icculus merged commit 57b6e6c into libsdl-org:main Jun 1, 2025
41 checks passed
icculus added a commit that referenced this pull request Jun 1, 2025
Just in case this ever get deinitialized sooner, we'd still like to SDL_free()
things on shutdown, etc.

Reference PR #13148.
icculus added a commit that referenced this pull request Jun 1, 2025
Just in case this ever get deinitialized sooner, we'd still like to SDL_free()
things on shutdown, etc.

Reference PR #13148.

(cherry picked from commit 9e0d9f3)
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.

2 participants