Don't use SDL devices that report invalid ranges.

If Buttons, Axes, Hats, or Balls > 255 then reject it.
This commit is contained in:
Ryan Houdek 2014-04-15 23:02:17 -05:00
parent 1f0da63cbe
commit c88b83699e
1 changed files with 11 additions and 0 deletions

View File

@ -78,6 +78,17 @@ Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsi
} }
#endif #endif
if (SDL_JoystickNumButtons(joystick) > 255 ||
SDL_JoystickNumAxes(joystick) > 255 ||
SDL_JoystickNumHats(joystick) > 255 ||
SDL_JoystickNumBalls(joystick) > 255)
{
// This device is invalid, don't use it
// Some crazy devices(HP webcam 2100) end up as HID devices
// SDL tries parsing these as joysticks
return;
}
// get buttons // get buttons
for (u8 i = 0; i != SDL_JoystickNumButtons(m_joystick); ++i) for (u8 i = 0; i != SDL_JoystickNumButtons(m_joystick); ++i)
AddInput(new Button(i, m_joystick)); AddInput(new Button(i, m_joystick));