Better fix, iterate backwards over the array so we don't care whether the close code shuffles things down.
authorSam Lantinga <slouken@libsdl.org>
Tue, 29 Nov 2011 02:27:34 -0500
changeset 6097 4ea2b4d4937a
parent 6096 71a57385664f
child 6098 c781fe3628a1
Better fix, iterate backwards over the array so we don't care whether the close code shuffles things down.
src/joystick/SDL_joystick.c
--- a/src/joystick/SDL_joystick.c	Tue Nov 29 02:15:39 2011 -0500
+++ b/src/joystick/SDL_joystick.c	Tue Nov 29 02:27:34 2011 -0500
@@ -403,8 +403,8 @@
     /* Stop the event polling */
     SDL_numjoysticks = 0;
 
-    for (i = 0; i < numsticks; i++) {
-        SDL_Joystick *stick = SDL_joysticks[0];
+    for (i = numjoysticks; i--; ) {
+        SDL_Joystick *stick = SDL_joysticks[i];
         if (stick && (stick->ref_count >= 1)) {
             stick->ref_count = 1;
             SDL_JoystickClose(stick);