diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-07 03:11:12 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-07 03:11:12 +0400 |
commit | 6a7a144f500b59334224f250c6a816ae5d7327bf (patch) | |
tree | 2e4f0368b508eb63c5f96cad3e8ad1d3ba6ddb1e /source | |
parent | a4c6e36aac7b7e99786198ce8a7f9ece5239365e (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp | 7 |
1 files 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)) |