Fix SDL3 joystick enumeration using device indices as instance IDs#182
Merged
Merged
Conversation
get_joysticks/get_controllers/_get_all passed range(count) indices into SDL_OpenJoystick/SDL_OpenGamepad/SDL_IsGamepad, which on SDL3 take an SDL_JoystickID instance ID. _get_number discarded the instance-ID array that SDL_GetJoysticks returns, so enumeration opened the wrong device or failed once instance IDs diverged from device indices (e.g. after a pad was reconnected). Replace _get_number with _get_instance_ids, which keeps and frees the SDL_GetJoysticks array, and enumerate by instance ID. Fixes libtcod#181
for more information, see https://pre-commit.ci
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
=======================================
Coverage 86.03% 86.03%
=======================================
Files 29 29
Lines 7583 7583
=======================================
Hits 6524 6524
Misses 1059 1059 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
HexDecimal
requested changes
Jun 4, 2026
Collaborator
HexDecimal
left a comment
There was a problem hiding this comment.
I clearly missed the details of SDL_GetJoysticks. Thanks for debugging this and making this PR.
Don't worry about code coverage. The code being short and clean is enough for now.
Co-authored-by: Kyle Benesch <4b796c65+github@gmail.com>
for more information, see https://pre-commit.ci
Contributor
Author
Roger
Thanks for all your work on the library! |
HexDecimal
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
get_joysticks/get_controllers/_get_all passed range(count) indices into
SDL_OpenJoystick/SDL_OpenGamepad/SDL_IsGamepad, which on SDL3 take an
SDL_JoystickID instance ID. _get_number discarded the instance-ID array
that SDL_GetJoysticks returns, so enumeration opened the wrong device or
failed once instance IDs diverged from device indices (e.g. after a pad
was reconnected).
Replace _get_number with _get_instance_ids, which keeps and frees the
SDL_GetJoysticks array, and enumerate by instance ID.
Fixes #181