We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 5254 - Wired PS4 Gamepad detected as two controllers on Mac
Summary: Wired PS4 Gamepad detected as two controllers on Mac
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: joystick (show other bugs)
Version: 2.0.12
Hardware: x86_64 macOS 10.15
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-11 13:18 UTC by sdlbugs
Modified: 2020-12-09 14:50 UTC (History)
1 user (show)

See Also:


Attachments
Patch to move SDL_HIDAPI_JoystickDriver to be checked before SDL_DARWIN_JoystickDriver (1.33 KB, application/mbox)
2020-08-11 13:18 UTC, sdlbugs
Details

Note You need to log in before you can comment on or make changes to this bug.
Description sdlbugs 2020-08-11 13:18:39 UTC
Created attachment 4435 [details]
Patch to move SDL_HIDAPI_JoystickDriver to be checked before SDL_DARWIN_JoystickDriver

If a USB connected PS4 gamepad is plugged into the mac while an SDL game is running you will receive two SDL_CONTROLLERDEVICEADDED messages for two new controllers. These will both be a copy of the new gamepad, and all button presses etc. will register on both controllers.

This still happens even if Bluetooth is disabled, so it's nothing to do with the joystick connecting twice through two channels.

It seems that the problem is that there are two drivers on Mac: 
- SDL_DARWIN_JoystickDriver
- SDL_HIDAPI_JoystickDriver

And both of these detect and add the new controller, hence two controllers.

The problem seems to be that SDL_HIDAPI_JoystickDriver does NOT check to see if the new controller is a duplicate when adding it, whereas SDL_DARWIN_JoystickDriver does.

If I swap the order of drivers in SDL_joystick_drivers[], so the HIDAPI driver comes first then it solves the problem and the gamepad only appears once, as SDL_Darwin_JoystickDriver notices the duplication. This isn't a great fix though, as it essentially relies on the drivers being called in a specific order.

A proper fix would be to have SDL_HIDAPI_JoystickDriver check for duplicates.
Comment 1 Sam Lantinga 2020-12-09 14:50:59 UTC
This is fixed for the 2.0.14 release.

Thanks!