From 9289249df5cda81a0d89dc5c0776920b28d02da1 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 24 Oct 2014 15:06:18 -0700 Subject: [PATCH] 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) {