Checks if Xinput2 is loaded before trying to call Xinput2 functions #13148
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes a crash if Xinput2 fails to load.
Description
If
SDL_VIDEO_DRIVER_X11_XINPUT2
andSDL_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