From 9289249df5cda81a0d89dc5c0776920b28d02da1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 Oct 2014 15:06:18 -0700 Subject: [PATCH 1/2] add a guard in case SDL somehow forgets about axes --- interface/src/devices/Joystick.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/interface/src/devices/Joystick.cpp b/interface/src/devices/Joystick.cpp index 25b8bc142d..a01b84e098 100644 --- a/interface/src/devices/Joystick.cpp +++ b/interface/src/devices/Joystick.cpp @@ -45,10 +45,12 @@ void Joystick::closeJoystick() { #ifdef HAVE_SDL2 void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) { - float oldValue = _axes[event.axis]; - float newValue = event.value / MAX_AXIS; - _axes[event.axis] = newValue; - emit axisValueChanged(event.axis, newValue, oldValue); + if (event.axis < _axes.size() - 1) { + float oldValue = _axes[event.axis]; + float newValue = event.value / MAX_AXIS; + _axes[event.axis] = newValue; + emit axisValueChanged(event.axis, newValue, oldValue); + } } void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) { From c57fc314f08b0725c891bdd144edcd9836b658a2 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 Oct 2014 15:13:54 -0700 Subject: [PATCH 2/2] just resize axis vector is sdl decides to lie about the number of axes --- interface/src/devices/Joystick.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/interface/src/devices/Joystick.cpp b/interface/src/devices/Joystick.cpp index a01b84e098..8b225437c2 100644 --- a/interface/src/devices/Joystick.cpp +++ b/interface/src/devices/Joystick.cpp @@ -45,12 +45,15 @@ void Joystick::closeJoystick() { #ifdef HAVE_SDL2 void Joystick::handleAxisEvent(const SDL_ControllerAxisEvent& event) { - if (event.axis < _axes.size() - 1) { - float oldValue = _axes[event.axis]; - float newValue = event.value / MAX_AXIS; - _axes[event.axis] = newValue; - emit axisValueChanged(event.axis, newValue, oldValue); + if (_axes.size() <= event.axis) { + _axes.resize(event.axis + 1); } + + float oldValue = _axes[event.axis]; + float newValue = event.value / MAX_AXIS; + _axes[event.axis] = newValue; + + emit axisValueChanged(event.axis, newValue, oldValue); } void Joystick::handleButtonEvent(const SDL_ControllerButtonEvent& event) {