Skip to content

fix(physics): widen contact pair key past the 16-bit overflow (A4)#155

Merged
Exoridus merged 1 commit into
mainfrom
feat/v0.14-a4-pairkey
Jun 22, 2026
Merged

fix(physics): widen contact pair key past the 16-bit overflow (A4)#155
Exoridus merged 1 commit into
mainfrom
feat/v0.14-a4-pairkey

Conversation

@Exoridus

Copy link
Copy Markdown
Owner

A4 — contact pair-key 16-bit overflow fix (v0.14 wave 1)

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 (_nextColliderId++), so a long-running world with heavy spawn/destroy churn can hit that ceiling.

  • Switch to multiplication by a 2^26 stride (pairKeyStride): 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.
  • New regression test (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

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.
@Exoridus Exoridus merged commit 2f77e8f into main Jun 22, 2026
12 checks passed
@Exoridus Exoridus deleted the feat/v0.14-a4-pairkey branch June 22, 2026 15:30
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