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:
Zwip-Zwap Zapony 2020-03-04 17:31:52 +01:00
parent 7d14796954
commit 27e084a827

View file

@ -1045,17 +1045,14 @@ static INT32 G_BasicDeadZoneCalculation(INT32 magnitude, fixed_t deadZone)
const INT32 jdeadzone = (JOYAXISRANGE * deadZone) / FRACUNIT;
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;