all repos — mgba @ aacab52a840f8c086a8fb22160c52f25fbe49032

mGBA Game Boy Advance Emulator

SDL: Ensure polled axes exist
Jeffrey Pfau jeffrey@endrift.com
Tue, 21 Apr 2015 21:36:34 -0700
commit

aacab52a840f8c086a8fb22160c52f25fbe49032

parent

e0185740f7dd45ea804f94f229ec65bbff520ca6

1 files changed, 5 insertions(+), 4 deletions(-)

jump to
M src/platform/sdl/sdl-events.csrc/platform/sdl/sdl-events.c

@@ -242,32 +242,33 @@ GBAInputProfileLoad(context->bindings, SDL_BINDING_BUTTON, config, name);

const char* value; char* end; + int numAxes = SDL_JoystickNumAxes(context->joystick); int axis; value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "tiltAxisX", name); if (value) { axis = strtol(value, &end, 0); - if (end && !*end) { + if (axis >= 0 && axis < numAxes && end && !*end) { context->rotation.axisX = axis; } } value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "tiltAxisY", name); if (value) { axis = strtol(value, &end, 0); - if (end && !*end) { + if (axis >= 0 && axis < numAxes && end && !*end) { context->rotation.axisY = axis; } } value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "gyroAxisX", name); if (value) { axis = strtol(value, &end, 0); - if (end && !*end) { + if (axis >= 0 && axis < numAxes && end && !*end) { context->rotation.gyroX = axis; } } value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "gyroAxisY", name); if (value) { axis = strtol(value, &end, 0); - if (end && !*end) { + if (axis >= 0 && axis < numAxes && end && !*end) { context->rotation.gyroY = axis; } }