Skip to content

Commit c508e9d

Browse files
committed
Handle wheelForce <= 1 in auto target calc
Add a guard in ConvertAutoMarginToAutoTarget to return wheelForce when wheelForce <= 1f to avoid clamping with min > max (which could throw an ArgumentException). Update comment to clarify that an unconfigured or very small wheel force has no meaningful target and should be returned as-is. This prevents crashes for contexts where wheelForce is below 1 Nm.
1 parent 165fd14 commit c508e9d

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

MarvinsAIRARefactored/DataContext/Settings.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,16 @@ public void MigrateAutoMarginToAutoTarget()
358358
}
359359

360360
// The old margin mapped the peak torque to WheelForce / (1 + margin) Nm - that torque is the new
361-
// auto target. Clamped to [1, WheelForce] so it never exceeds the wheel force.
361+
// auto target. Clamped to [1, WheelForce] so it never exceeds the wheel force. If the wheel force is
362+
// below 1 Nm (e.g. an unconfigured context), there is no meaningful target, so just return the wheel
363+
// force itself - clamping with min > max would throw an ArgumentException.
362364
private static float ConvertAutoMarginToAutoTarget( float wheelForce, float autoMargin )
363365
{
366+
if ( wheelForce <= 1f )
367+
{
368+
return wheelForce;
369+
}
370+
364371
var autoTarget = wheelForce / ( 1f + autoMargin );
365372

366373
return Math.Clamp( autoTarget, 1f, wheelForce );

0 commit comments

Comments
 (0)