From 6a7a144f500b59334224f250c6a816ae5d7327bf Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Sun, 6 Jan 2013 23:11:12 +0000 Subject: BGE: Fix for [#33053] "2.6x Joystick Sensor Event: Axis fails to fire at full tilt" reported by Auuman Anubis (auuman_anubis). The problem was that SCA_Joystick::pAxisTest() was using shorts, and tried to store abs(MIN_SHRT) in a short. However, on most systems MIN_SHRT == -32768 and MAX_SHRT == 32767. This means that abs(MIN_SHRT) > MAX_SHRT, and thus the short would overflow. --- source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp index b7fbe958c86..dce62ad189a 100644 --- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp +++ b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp @@ -307,8 +307,11 @@ int SCA_Joystick::pGetAxis(int axisnum, int udlr) int SCA_Joystick::pAxisTest(int axisnum) { #ifdef WITH_SDL - short i1 = m_axis_array[(axisnum * 2)]; - short i2 = m_axis_array[(axisnum * 2) + 1]; + /* Use ints instead of shorts here to avoid problems when we get -32768. + * When we take the negative of that later, we should get 32768, which is greater + * than what a short can hold. In other words, abs(MIN_SHORT) > MAX_SHRT. */ + int i1 = m_axis_array[(axisnum * 2)]; + int i2 = m_axis_array[(axisnum * 2) + 1]; /* long winded way to do: * return max_ff(absf(i1), absf(i2)) -- cgit v1.2.3