Skip to content

Commit

Permalink
Fix crash when creating XInput thumb gestures at min/max position
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoooi0 committed Jun 19, 2024
1 parent bb1bb0b commit c93917d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Source/MultiFunPlayer/Input/XInput/XInputProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MultiFunPlayer.Common;
using MultiFunPlayer.Common;
using Newtonsoft.Json;
using NLog;
using Stylet;
Expand Down Expand Up @@ -106,12 +106,13 @@ void CreateAxisGestureShort(short last, short current, double deadZone, GamepadA
{
if (current == last)
return;
if (Math.Abs(current) < deadZone && Math.Abs(last) < deadZone)
return;

var currentValue = UnLerpShort(current, deadZone);
var lastValue = UnLerpShort(last, deadZone);
var delta = Math.Clamp(currentValue - lastValue, -1, 1);
if (delta == 0)
return;

PublishGesture(GamepadAxisGesture.Create(userIndex, axis, currentValue, delta, elapsed));

static double UnLerpShort(short value, double deadZone) => 0.5 + value switch
Expand Down

0 comments on commit c93917d

Please sign in to comment.