| Summary: | Playstation 4 Controllers listed twice at the startup when a Playstation 3 controller is also connected | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Rodrigo Cardoso <rodrigo.alfenas> |
| Component: | joystick | Assignee: | Ryan C. Gordon <icculus> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | major | ||
| Priority: | P2 | CC: | amaranth72, computers57, icculus, rodrigo.alfenas, tomyun |
| Version: | 2.0.3 | ||
| Hardware: | x86 | ||
| OS: | Mac OS X (All) | ||
|
Description
Rodrigo Cardoso
2014-08-24 21:01:24 UTC
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;
}
}
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. 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. 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. It IS fixed. Thank you! *** Bug 2511 has been marked as a duplicate of this bug. *** 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. |