Mac: Don't add the same joystick twice if IOKit reports a duplicate device.

Fixes Bugzilla #2704.
This commit is contained in:
Ryan C. Gordon 2014-08-31 11:21:10 -04:00
parent 7e515963a6
commit 724d24d990

View File

@ -364,15 +364,33 @@ GetDeviceInfo(IOHIDDeviceRef hidDevice, recDevice *pDevice)
return SDL_TRUE; return SDL_TRUE;
} }
static SDL_bool
JoystickAlreadyKnown(IOHIDDeviceRef ioHIDDeviceObject)
{
recDevice *i;
for (i = gpDeviceList; i != NULL; i = i->pNext) {
if (i->deviceRef == ioHIDDeviceObject) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
static void static void
JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject) JoystickDeviceWasAddedCallback(void *ctx, IOReturn res, void *sender, IOHIDDeviceRef ioHIDDeviceObject)
{ {
recDevice *device;
if (res != kIOReturnSuccess) { if (res != kIOReturnSuccess) {
return; return;
} }
recDevice *device = (recDevice *) SDL_calloc(1, sizeof(recDevice)); if (JoystickAlreadyKnown(ioHIDDeviceObject)) {
return; /* IOKit sent us a duplicate. */
}
device = (recDevice *) SDL_calloc(1, sizeof(recDevice));
if (!device) { if (!device) {
SDL_OutOfMemory(); SDL_OutOfMemory();