Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playstation 4 Controllers listed twice at the startup when a Playstation 3 controller is also connected #1620

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: 2.0.3
Reported for operating system, platform: Mac OS X (All), x86

Comments on the original bug report:

On 2014-08-24 21:01:24 +0000, Rodrigo Cardoso wrote:

First of all I am using the latest SDL snapshot ( as of this writing, https://hg.libsdl.org/SDL/rev/da2bbecb7ad0 )

Description:

When I start my application with a PS4 controller AND a PS3 controller connected via bluetooth on Mac OS X (tested on 10.9 and 10.10 developer preview), the PS4 controller gets listed twice.

This does happen in these cases:

  • opening all joysticks when starting the app
  • restarting the SDL joystick subsystem and doing the same thing above.
  • Letting the hotplug code handle the joystick openning, without opening all the joysticks from its index separatelly.

This does NOT happen in these cases:

  • hotpluging in any order
  • when I have another kind of controller connected togheter instead of a Dual Shock 3. (tested with a xbox 360 controller)

Not sure if this is related:
https://hg.libsdl.org/SDL/rev/f6a2b1a6932b

This guy appears to have the same problem i am reporting here:
http://steamcommunity.com/app/251470/discussions/0/540743212865042085/

This bug seems similar, but with other devices:
https://bugzilla.libsdl.org/show_bug.cgi?id=2511

On 2014-08-24 21:19:39 +0000, Rodrigo Cardoso wrote:

Some snaps of the code I used to test:

void loop() {
SDL_Event e;
while (SDL_PollEvent(&e)) {
switch (e.type) {
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
case SDL_JOYHATMOTION:
case SDL_JOYAXISMOTION:
{
printf("[%d] Joystick (%d) did something\n", e.common.timestamp, e.jbutton.which);
break;
}
case SDL_JOYDEVICEADDED:
{
int success = openJoystick(e.jdevice.which);
if(success)
printf("[%d] Joystick (%d) openned\n", e.common.timestamp, e.jdevice.which);
break;
}
case SDL_JOYDEVICEREMOVED:
{
int success = closeJoystickWithInstanceId(e.jdevice.which);
if(success)
printf("[%d] Joystick (%d) closed\n", e.common.timestamp, e.jdevice.which);
break;
}
default:
break;
}
}
SDL_Delay(delayTime);
}

int openJoystick(int which) {
SDL_Joystick * j = SDL_JoystickOpen(device_index);
if (!j) return 0;
/* stored key SDL_JoystickInstanceID value j pair here */
addJoystick(which, j);
return 1;
}

int closeJoystickWithInstanceId(int instanceId) {
SDL_Joystick *j = getJoystickWithId(instanceId);

if (j != NULL) {
SDL_JoystickClose(j);
removeJoystickFromList(instanceId);
return 1;
}

return 0;
}

void openAllJoysticks() {
SDL_Event e;
while (SDL_PollEvent(&e)) {}; // discard events
SDL_JoystickUpdate();

int numJoysticks = SDL_NumJoysticks();
for (int i = 0; i < numJoysticks; ++i) {
if (!openJoystick(i)) return NO;
}
}

On 2014-08-26 05:53:09 +0000, Rodrigo Cardoso wrote:

Seems like ANY other controllers connected gets duplicated entries at the start up when a PS3 controller is also connected......

This apparently got cleaned when you disconnect and reconnect each controller.

On 2014-08-26 21:01:04 +0000, Alex Szpakowski wrote:

It seems that way to me as well: if I have an Xbox controller and a PS3 controller connected at startup, the Xbox controller is listed twice. If I have just one connected at startup and then connect the other during runtime everything is OK, and if I disconnect and reconnect one during runtime (if both were connected at startup) then it will also list the proper number of controllers.

On 2014-08-31 15:25:44 +0000, Ryan C. Gordon wrote:

This should be fixed in https://hg.libsdl.org/SDL/rev/b186c0df3c18 ... it looks like IOKit sends us one (random?) joystick when you first set up the "call this function when a device is added" callback and then it sends all the known devices when you start the event runloop (which is what we expected).

Not sure if this is a bug in IOKit, or something PS3 specific, or my misunderstanding the documentation, or what, but just making sure we don't already have the device in our list fixes the issue and makes the code more robust anyhow.

Please test and report back.

Thanks!

--ryan.

On 2014-09-04 21:50:56 +0000, Rodrigo Cardoso wrote:

It IS fixed. Thank you!

On 2014-09-23 08:32:35 +0000, Rodrigo Cardoso wrote:

*** Bug 2511 has been marked as a duplicate of this bug. ***

On 2014-12-17 06:12:09 +0000, Kyungdahm Yun wrote:

I just came across this ticket after reporting # 2822, presumably the same issue with my own patch.

It seems HEAD branch already got fixed with a patch that rejects any duplicate joystick being reported. Meanwhile, my patch is supposed to eliminate redundant reporting from IOKit before running into the event loop.

I'm not sure if this would really fix all edge cases, but it's just one liner, so please take a look. In my opinion, having two patches altogether should not hurt anyways.

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

No branches or pull requests

1 participant