Commit c974c5cf authored by Richard Gobeille's avatar Richard Gobeille
Browse files

engine: cap joystick .numAxes and .numButtons to the highest index actually...

engine: cap joystick .numAxes and .numButtons to the highest index actually valid for the current controller

Since there's no function to just return the number of valid axes and buttons, I suspect SDL expects us to keep track of which indexes are valid ourselves as the range of valid values may not be contiguous. We aren't doing that yet.
parent 9326d7a3
......@@ -944,7 +944,7 @@ void joyScanDevices()
buildprintf(" %d. %s\n", i+1, name);
}
#if SDL_MAJOR_VERSION >= 2
for (int i = 0; i < numjoysticks; i++)
{
......@@ -952,17 +952,30 @@ void joyScanDevices()
{
buildprintf("Using controller %s\n", SDL_GameControllerName(controller));
joystick.numAxes = SDL_CONTROLLER_AXIS_MAX;
joystick.numBalls = 0;
joystick.numButtons = SDL_CONTROLLER_BUTTON_MAX;
joystick.numHats = 0;
joystick.numAxes = SDL_CONTROLLER_AXIS_MAX;
joystick.numButtons = SDL_CONTROLLER_BUTTON_MAX;
#if SDL_MINOR_VERSION > 0 || SDL_PATCHLEVEL >= 14
if (EDUKE32_SDL_LINKED_PREREQ(linked, 2, 0, 14))
{
joystick.numAxes = 0;
for (int j = 0; j < SDL_CONTROLLER_AXIS_MAX; ++j)
if (SDL_GameControllerHasAxis(controller, (SDL_GameControllerAxis)j))
joystick.numAxes = j + 1;
joystick.numButtons = 0;
for (int j = 0; j < SDL_CONTROLLER_BUTTON_MAX; ++j)
if (SDL_GameControllerHasButton(controller, (SDL_GameControllerButton)j))
joystick.numButtons = j + 1;
}
#endif
joystick.isGameController = 1;
Xfree(joystick.pAxis);
joystick.pAxis = (int32_t *)Xcalloc(joystick.numAxes, sizeof(int32_t));
Xfree(joystick.pHat);
joystick.pHat = nullptr;
DO_FREE_AND_NULL(joystick.pHat);
inputdevices |= 4;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment