mirror of https://github.com/mgba-emu/mgba.git
SDL: Ensure polled axes exist
This commit is contained in:
parent
e0185740f7
commit
aacab52a84
|
@ -242,32 +242,33 @@ void GBASDLPlayerLoadConfig(struct GBASDLPlayer* context, const struct Configura
|
||||||
|
|
||||||
const char* value;
|
const char* value;
|
||||||
char* end;
|
char* end;
|
||||||
|
int numAxes = SDL_JoystickNumAxes(context->joystick);
|
||||||
int axis;
|
int axis;
|
||||||
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "tiltAxisX", name);
|
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "tiltAxisX", name);
|
||||||
if (value) {
|
if (value) {
|
||||||
axis = strtol(value, &end, 0);
|
axis = strtol(value, &end, 0);
|
||||||
if (end && !*end) {
|
if (axis >= 0 && axis < numAxes && end && !*end) {
|
||||||
context->rotation.axisX = axis;
|
context->rotation.axisX = axis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "tiltAxisY", name);
|
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "tiltAxisY", name);
|
||||||
if (value) {
|
if (value) {
|
||||||
axis = strtol(value, &end, 0);
|
axis = strtol(value, &end, 0);
|
||||||
if (end && !*end) {
|
if (axis >= 0 && axis < numAxes && end && !*end) {
|
||||||
context->rotation.axisY = axis;
|
context->rotation.axisY = axis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "gyroAxisX", name);
|
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "gyroAxisX", name);
|
||||||
if (value) {
|
if (value) {
|
||||||
axis = strtol(value, &end, 0);
|
axis = strtol(value, &end, 0);
|
||||||
if (end && !*end) {
|
if (axis >= 0 && axis < numAxes && end && !*end) {
|
||||||
context->rotation.gyroX = axis;
|
context->rotation.gyroX = axis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "gyroAxisY", name);
|
value = GBAInputGetCustomValue(config, SDL_BINDING_BUTTON, "gyroAxisY", name);
|
||||||
if (value) {
|
if (value) {
|
||||||
axis = strtol(value, &end, 0);
|
axis = strtol(value, &end, 0);
|
||||||
if (end && !*end) {
|
if (axis >= 0 && axis < numAxes && end && !*end) {
|
||||||
context->rotation.gyroY = axis;
|
context->rotation.gyroY = axis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue