fix(physics): widen contact pair key past the 16-bit overflow (A4)#155
Merged
Conversation
ContactGraph packed collider id pairs as `(a.id << 16) | b.id`, which silently collided once any collider id reached 65536 — JS bitwise operators wrap at 32 bits. Collider ids are allocated monotonically and never recycled, so a long-running world with heavy spawn/destroy churn can hit that ceiling. Switch to multiplication by a 2^26 stride (`pairKeyStride`), keeping pair keys collision-free up to ~67M ids per world within JS's 2^53 safe-integer range. `pairKey` now takes the two ids directly (testable) and is exported `@internal`. Adds a regression test covering ids past 65535 and the old-scheme collision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A4 — contact pair-key 16-bit overflow fix (v0.14 wave 1)
ContactGraphpacked collider id pairs as(a.id << 16) | b.id, which silently collided once any collider id reached 65536 — JS bitwise operators wrap at 32 bits. Collider ids are allocated monotonically and never recycled (_nextColliderId++), so a long-running world with heavy spawn/destroy churn can hit that ceiling.pairKeyStride): collision-free up to ~67M ids per world, within JS's 2^53 safe-integer range.pairKeynow takes the two ids directly (testable) and is exported@internal.test/pair-key.test.ts) covering ids past 65535, safe-integer bounds, and the exact old-scheme collision.Verification (local)
physics typecheck · physics test suite (3 new pair-key tests) · lint:packages · format:check