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

Summary: Wired PS4 Gamepad detected as two controllers on Mac
Product: SDL Reporter: sdlbugs
Component: joystickAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: sezeroz
Version: 2.0.12   
Hardware: x86_64   
OS: macOS 10.15   
Attachments: Patch to move SDL_HIDAPI_JoystickDriver to be checked before SDL_DARWIN_JoystickDriver

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!