mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-18 07:22:28 +00:00
Fix division-by-0 crash with gamepad deadzones
Fix division-by-0 crash with gamepad deadzones The problem was that it checked if A was more than B, then lowered A to a max value, then subtracted B from A, then divided something by that, without checking if A minus B was 0, allowing division by 0 if B was the same as that max value This fixes that by making sure that A is less than the max value
This commit is contained in:
parent
7d14796954
commit
27e084a827
1 changed files with 5 additions and 8 deletions
13
src/g_game.c
13
src/g_game.c
|
@ -1045,17 +1045,14 @@ static INT32 G_BasicDeadZoneCalculation(INT32 magnitude, fixed_t deadZone)
|
||||||
const INT32 jdeadzone = (JOYAXISRANGE * deadZone) / FRACUNIT;
|
const INT32 jdeadzone = (JOYAXISRANGE * deadZone) / FRACUNIT;
|
||||||
INT32 deadzoneAppliedValue = 0;
|
INT32 deadzoneAppliedValue = 0;
|
||||||
|
|
||||||
if (jdeadzone > 0)
|
if (jdeadzone > 0 && magnitude > jdeadzone && deadZone < FRACUNIT)
|
||||||
{
|
{
|
||||||
if (magnitude > jdeadzone)
|
INT32 adjustedMagnitude = abs(magnitude);
|
||||||
{
|
adjustedMagnitude = min(adjustedMagnitude, JOYAXISRANGE);
|
||||||
INT32 adjustedMagnitude = abs(magnitude);
|
|
||||||
adjustedMagnitude = min(adjustedMagnitude, JOYAXISRANGE);
|
|
||||||
|
|
||||||
adjustedMagnitude -= jdeadzone;
|
adjustedMagnitude -= jdeadzone;
|
||||||
|
|
||||||
deadzoneAppliedValue = (adjustedMagnitude * JOYAXISRANGE) / (JOYAXISRANGE - jdeadzone);
|
deadzoneAppliedValue = (adjustedMagnitude * JOYAXISRANGE) / (JOYAXISRANGE - jdeadzone);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return deadzoneAppliedValue;
|
return deadzoneAppliedValue;
|
||||||
|
|
Loading…
Reference in a new issue