diff --git a/src/Input.cpp b/src/Input.cpp index 2e09de12..219b2e99 100644 --- a/src/Input.cpp +++ b/src/Input.cpp @@ -60,11 +60,14 @@ BOOL GetJoystickStatus(JOYSTICK_STATUS *status) if (joystick == NULL) return FALSE; + // The original Input.cpp assumed there were 32 buttons (because of DirectInput's 'DIJOYSTATE' struct) int numButtons = SDL_JoystickNumButtons(joystick); if (numButtons > 32) numButtons = 32; - for (int i = 0; i < numButtons; ++i) + // Read whatever buttons actually exist + int i; + for (i = 0; i < numButtons; ++i) { if (SDL_JoystickGetButton(joystick, i) != 0) status->bButton[i] = TRUE; @@ -72,6 +75,10 @@ BOOL GetJoystickStatus(JOYSTICK_STATUS *status) status->bButton[i] = FALSE; } + // Blank the buttons that do not + for (; i < 32; ++i) + status->bButton[i] = FALSE; + status->bDown = FALSE; status->bRight = FALSE; status->bUp = FALSE;