mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-15 01:56:51 +00:00
Merge branch 'deadzone-sigfpe-fix' into 'master'
Fix division-by-0 crash from 100% gamepad deadzones, and lack of input from 0% deadzones See merge request STJr/SRB2!838
This commit is contained in:
commit
f3a275930b
1 changed files with 7 additions and 8 deletions
15
src/g_game.c
15
src/g_game.c
|
|
@ -1044,18 +1044,17 @@ static INT32 G_BasicDeadZoneCalculation(INT32 magnitude, fixed_t deadZone)
|
|||
{
|
||||
const INT32 jdeadzone = (JOYAXISRANGE * deadZone) / FRACUNIT;
|
||||
INT32 deadzoneAppliedValue = 0;
|
||||
INT32 adjustedMagnitude = abs(magnitude);
|
||||
|
||||
if (jdeadzone > 0)
|
||||
if (jdeadzone >= JOYAXISRANGE && adjustedMagnitude >= JOYAXISRANGE) // If the deadzone and magnitude are both 100%...
|
||||
return JOYAXISRANGE; // ...return 100% input directly, to avoid dividing by 0
|
||||
else if (adjustedMagnitude > jdeadzone) // Otherwise, calculate how much the magnitude exceeds the deadzone
|
||||
{
|
||||
if (magnitude > jdeadzone)
|
||||
{
|
||||
INT32 adjustedMagnitude = abs(magnitude);
|
||||
adjustedMagnitude = min(adjustedMagnitude, JOYAXISRANGE);
|
||||
adjustedMagnitude = min(adjustedMagnitude, JOYAXISRANGE);
|
||||
|
||||
adjustedMagnitude -= jdeadzone;
|
||||
adjustedMagnitude -= jdeadzone;
|
||||
|
||||
deadzoneAppliedValue = (adjustedMagnitude * JOYAXISRANGE) / (JOYAXISRANGE - jdeadzone);
|
||||
}
|
||||
deadzoneAppliedValue = (adjustedMagnitude * JOYAXISRANGE) / (JOYAXISRANGE - jdeadzone);
|
||||
}
|
||||
|
||||
return deadzoneAppliedValue;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue