Skip to content

[WIP] SDL2 on macOS detects joysticks only with SDL2_INIT_VIDEO#302

Open
EliaCereda wants to merge 2 commits into
ros-drivers:ros2from
EliaCereda:ros2-macos
Open

[WIP] SDL2 on macOS detects joysticks only with SDL2_INIT_VIDEO#302
EliaCereda wants to merge 2 commits into
ros-drivers:ros2from
EliaCereda:ros2-macos

Conversation

@EliaCereda

Copy link
Copy Markdown

SDL2 on macOS seems to have issues detecting joysticks that are already connected at startup (I started a discussion here: libsdl-org/SDL#12886).

I'm opening a PR to share this workaround that seems to make everything work correctly, but it's not a proper fix right now. I'm sure initialising SDL2_INIT_VIDEO is not very desirable, especially not on other platforms, as it prevents the joy node from running headless.

Was this a known issue?

@peci1

peci1 commented Feb 15, 2026

Copy link
Copy Markdown
Contributor

This PR seems to contain a lot of unrelated changes. Or are they related?

I think this workaround has to be enabled by a parameter (that defaults to false).

@EliaCereda

Copy link
Copy Markdown
Author

Sorry for not noticing your reply earlier @peci1.

Ideally SDL would fix this upstream, by properly setting up the macOS event loop even without SDL2_INIT_VIDEO. At the moment my issue there is still open:
libsdl-org/SDL#12886

In the meantime, my changes are indeed related: in joy.cpp, once you enable SDL2_INIT_VIDEO, the change to eventThread is needed to call SDL_WaitEventTimeout from the main thread. That's because macOS GUI APIs can only be invoked from the main thread. IIRC they would throw an assertion without the change.

The changes to joy_enumerate_devices.cpp on the other hand are needed because joysticks are discovered asynchronously on macOS. If you just enumerate them at startup you would get an empty loop.

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