Only allocate a joystick instance ID once we know it's a joystick.
authorSam Lantinga <slouken@libsdl.org>
Sun, 06 Oct 2013 20:39:23 -0700
changeset 7791 d9f0067a5421
parent 7790 8136ce6b3950
child 7792 b8d4be87970a
Only allocate a joystick instance ID once we know it's a joystick. This fixes compatibility with code that assumes 0 based joystick instance IDs.
src/joystick/darwin/SDL_sysjoystick.c
--- a/src/joystick/darwin/SDL_sysjoystick.c	Sun Oct 06 13:50:36 2013 -0700
+++ b/src/joystick/darwin/SDL_sysjoystick.c	Sun Oct 06 20:39:23 2013 -0700
@@ -589,7 +589,6 @@
             if (kIOReturnSuccess == result) {
                 HIDGetDeviceInfo(hidDevice, hidProperties, pDevice);    /* hidDevice used to find parents in registry tree */
                 HIDGetCollectionElements(hidProperties, pDevice);
-                pDevice->instance_id = ++s_joystick_instance_id;
             } else {
                 DisposePtr((Ptr) pDevice);
                 pDevice = NULL;
@@ -678,6 +677,9 @@
         return 0;
     }
 
+    /* Allocate an instance ID for this device */
+    device->instance_id = ++s_joystick_instance_id;
+
     /* We have to do some storage of the io_service_t for
      * SDL_HapticOpenFromJoystick */
     if (FFIsForceFeedback(ioHIDDeviceObject) == FF_OK) {