Skip to content

Fix a crash on narrow roads: clamp in MM2's order (0.3.1) - #4

Merged
lowlevelmetal merged 2 commits into
mainfrom
integration
Oct 9, 2026
Merged

lowlevelmetal merged 2 commits into
mainfrom
integration

Conversation

@lowlevelmetal

Copy link
Copy Markdown
Owner

Fixes a crash in a race: std::clamp ... Assertion '!(__hi < __lo)' failed (float). Version 0.3.1; the network protocol is unchanged.

aiVehiclePhysics::CalcRoadTarget and CalcDestinationTarget clamp a target's offset across a road to ±h, where h is the road's half-width less the car's side and 1 m. On a road narrower than that, h is negative.

  • OpenMM2 used std::clamp, whose bounds must be ordered. A build with libstdc++'s assertions (a GCC 15+ debug build) aborted. An optimised build returned h where MM2 returns -h.
  • MM2 compares the lower bound first. The new ai::clampAcross keeps that order at all seven sites in DrivingTargets.cpp.

Testing:

  • New parity test ParityAiRoute.ClampAcrossKeepsMm2sOrderOnANarrowRoad.
  • Full suite with game data: 926/926. Sweep unchanged: 516/517 finished, 508/517 across the line.
  • The full suite and the sweep also pass in a build with -D_GLIBCXX_ASSERTIONS, with no aborts.
  • A parse of every std::clamp call found no other float clamp whose bounds can cross in a race.

🤖 Generated with Claude Code

lowlevelmetal and others added 2 commits October 9, 2026 11:29
aiVehiclePhysics::CalcRoadTarget and CalcDestinationTarget clamp the
target's offset across a road to +-h, h being the road's half-width less
the car's side and 1 m, comparing the lower bound first: below -h gives -h,
otherwise above h gives h. On a road narrower than that h is negative.
OpenMM2 used std::clamp there, whose bounds must be ordered: a build with
libstdc++'s assertions (a GCC 15+ debug build) aborted in a race with
"Assertion '!(__hi < __lo)' failed", and an optimised one returned h
where MM2 returns -h. ai::clampAcross keeps MM2's comparisons.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@lowlevelmetal
lowlevelmetal merged commit cd5ae29 into main Oct 9, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant