Fix device counting in HapticMouse and JoystickOpen routines. 0 is the first item in the list not the last
authorEdward Rudd <urkle@outoforder.cc>
Thu, 06 Feb 2014 09:35:44 -0500
changeset 8183 f8404b0e00ac
parent 8182 92f71edde3be
child 8184 2afb90ff0199
Fix device counting in HapticMouse and JoystickOpen routines. 0 is the first item in the list not the last
src/haptic/darwin/SDL_syshaptic.c
src/haptic/linux/SDL_syshaptic.c
src/haptic/windows/SDL_syshaptic.c
--- a/src/haptic/darwin/SDL_syshaptic.c	Thu Feb 06 09:11:05 2014 -0500
+++ b/src/haptic/darwin/SDL_syshaptic.c	Thu Feb 06 09:35:44 2014 -0500
@@ -199,7 +199,7 @@
 
     while (device_index > 0) {
         SDL_assert(item != NULL);
-        device_index--;
+        --device_index;
         item = item->next;
     }
 
@@ -571,7 +571,7 @@
 int
 SDL_SYS_HapticMouse(void)
 {
-    int device_index = numhaptics-1;
+    int device_index = 0;
     SDL_hapticlist_item *item;
 
     for (item = SDL_hapticlist; item; item = item->next) {
@@ -579,7 +579,7 @@
             (item->usage == kHIDUsage_GD_Mouse)) {
             return device_index;
         }
-        device_index--;
+        ++device_index;
     }
 
     return -1;
--- a/src/haptic/linux/SDL_syshaptic.c	Thu Feb 06 09:11:05 2014 -0500
+++ b/src/haptic/linux/SDL_syshaptic.c	Thu Feb 06 09:35:44 2014 -0500
@@ -202,7 +202,7 @@
 
     while (device_index > 0) {
         SDL_assert(item != NULL);
-        device_index--;
+        --device_index;
         item = item->next;
     }
 
--- a/src/haptic/windows/SDL_syshaptic.c	Thu Feb 06 09:11:05 2014 -0500
+++ b/src/haptic/windows/SDL_syshaptic.c	Thu Feb 06 09:35:44 2014 -0500
@@ -442,7 +442,7 @@
 
     while (device_index > 0) {
         SDL_assert(item != NULL);
-        device_index--;
+        --device_index;
         item = item->next;
     }
 
@@ -784,7 +784,7 @@
 SDL_SYS_HapticMouse(void)
 {
     SDL_hapticlist_item *item;
-    int index = numhaptics-1;
+    int index = 0;
 
     /* Grab the first mouse haptic device we find. */
     for (item = SDL_hapticlist; item != NULL; item = item->next) {
@@ -792,7 +792,7 @@
         if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) {
             return index;
         }
-        index--;
+        ++index;
     }
 
     return -1;
@@ -855,7 +855,7 @@
 SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
 {
     SDL_hapticlist_item *item;
-    int index = numhaptics-1;
+    int index = 0;
 
     /* Since it comes from a joystick we have to try to match it with a haptic device on our haptic list. */
     if (joystick->hwdata->bXInputDevice) {
@@ -866,7 +866,7 @@
                 haptic->index = index;
                 return SDL_SYS_HapticOpenFromXInput(haptic, userid);
             }
-            index--;
+            ++index;
         }
     } else {
         HRESULT idret;
@@ -883,7 +883,7 @@
                 haptic->index = index;
                 return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
             }
-            index--;
+            ++index;
         }
     }