Fix device counting in HapticMouse and JoystickOpen routines. 0 is the first item in the list not the last
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
diff --git a/src/haptic/darwin/SDL_syshaptic.c b/src/haptic/darwin/SDL_syshaptic.c
index beef010..306eda9 100644
--- a/src/haptic/darwin/SDL_syshaptic.c
+++ b/src/haptic/darwin/SDL_syshaptic.c
@@ -199,7 +199,7 @@ HapticByDevIndex(int device_index)
while (device_index > 0) {
SDL_assert(item != NULL);
- device_index--;
+ --device_index;
item = item->next;
}
@@ -571,7 +571,7 @@ SDL_SYS_HapticOpen(SDL_Haptic * haptic)
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 @@ SDL_SYS_HapticMouse(void)
(item->usage == kHIDUsage_GD_Mouse)) {
return device_index;
}
- device_index--;
+ ++device_index;
}
return -1;
diff --git a/src/haptic/linux/SDL_syshaptic.c b/src/haptic/linux/SDL_syshaptic.c
index 764434f..558177b 100644
--- a/src/haptic/linux/SDL_syshaptic.c
+++ b/src/haptic/linux/SDL_syshaptic.c
@@ -202,7 +202,7 @@ HapticByDevIndex(int device_index)
while (device_index > 0) {
SDL_assert(item != NULL);
- device_index--;
+ --device_index;
item = item->next;
}
diff --git a/src/haptic/windows/SDL_syshaptic.c b/src/haptic/windows/SDL_syshaptic.c
index a68cd34..6be0e4d 100644
--- a/src/haptic/windows/SDL_syshaptic.c
+++ b/src/haptic/windows/SDL_syshaptic.c
@@ -442,7 +442,7 @@ HapticByDevIndex(int device_index)
while (device_index > 0) {
SDL_assert(item != NULL);
- device_index--;
+ --device_index;
item = item->next;
}
@@ -784,7 +784,7 @@ int
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 @@ SDL_SYS_HapticMouse(void)
if (item->capabilities.dwDevType == DI8DEVCLASS_POINTER ) {
return index;
}
- index--;
+ ++index;
}
return -1;
@@ -855,7 +855,7 @@ int
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 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
haptic->index = index;
return SDL_SYS_HapticOpenFromXInput(haptic, userid);
}
- index--;
+ ++index;
}
} else {
HRESULT idret;
@@ -883,7 +883,7 @@ SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
haptic->index = index;
return SDL_SYS_HapticOpenFromDevice8(haptic, joystick->hwdata->InputDevice, SDL_TRUE);
}
- index--;
+ ++index;
}
}