Skip to content

Fix space mouse detection with SDL_hidapi - #7665

Open
MjnMixael wants to merge 1 commit into
scp-fs2open:masterfrom
MjnMixael:qtfred-spacemouse-fix
Open

Fix space mouse detection with SDL_hidapi#7665
MjnMixael wants to merge 1 commit into
scp-fs2open:masterfrom
MjnMixael:qtfred-spacemouse-fix

Conversation

@MjnMixael

Copy link
Copy Markdown
Contributor

Since #7646 switched from the bundled hidapi to SDL_hidapi, no space mouse is ever found: the standalone hidapi's hid_enumerate() implicitly initialized the library, but SDL's SDL_hid_enumerate() does not reliably do so, so it returns an empty device list and getSharedSpaceMouse() caches nullptr for the session.

Call SDL_hid_init() before enumerating, matching SDL's documented usage.

@MjnMixael MjnMixael added the qtfred A feature or issue related to qtFred. label Jul 28, 2026
@github-project-automation github-project-automation Bot moved this to Work In Progress (PRs) in qtFRED2 Jul 29, 2026
@github-project-automation github-project-automation Bot moved this from Work In Progress (PRs) to In Review (PRs) in qtFRED2 Jul 29, 2026
BMagnu
BMagnu previously requested changes Jul 29, 2026

@BMagnu BMagnu left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, looking at the discussion in #7646, SDL_hid_init/SDL_hid_exit must match. So adding an _init means this needs to also add an _exit on destruction

@notimaginative notimaginative left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDL_hid_enumerate() will call SDL_hid_init() if it has not already been initialized. The code previously did that, as addressed by the stale SDL_hid_exit() call mentioned in the PR. It was removed since it shouldn't be necessary.

However if SDL_hid_init() really needs to be called then we really need to do it before SDL is initialized (i.e., put it in os_init()) and a companion SDL_hid_exit() should be added as well (os_deinit()).

Since scp-fs2open#7646 switched from the bundled hidapi to SDL_hidapi, no space mouse is
found. SDL_hid_enumerate() nominally auto-inits HIDAPI, but in practice it only
reliably reports an already-connected device when SDL_hid_init() has been called
up front. Call SDL_hid_init() once in os_init() (before SDL_Init), balanced by
SDL_hid_exit() in os_deinit(). io::spacemouse (qtFRED's only consumer) then
enumerates the device correctly.
@MjnMixael
MjnMixael force-pushed the qtfred-spacemouse-fix branch from 8997e16 to b7b0915 Compare July 29, 2026 02:34
@MjnMixael

Copy link
Copy Markdown
Contributor Author

SDL_hid_enumerate() will call SDL_hid_init() if it has not already been initialized. The code previously did that, as addressed by the stale SDL_hid_exit() call mentioned in the PR. It was removed since it shouldn't be necessary.

However if SDL_hid_init() really needs to be called then we really need to do it before SDL is initialized (i.e., put it in os_init()) and a companion SDL_hid_exit() should be added as well (os_deinit()).

Without SDL_hid_init() spacemouse did not work in QtFRED. So I guess this is needed. I've changed it as requested and tested. This version does still fix the issue.

@BMagnu
BMagnu dismissed their stale review July 29, 2026 02:37

Seems okay to me, but I'll leave the authoritative approve to taylor.

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

Labels

qtfred A feature or issue related to qtFred.

Projects

Status: In Review (PRs)

Development

Successfully merging this pull request may close these issues.

3 participants