Fix physics use-after-free crash for offscreen display objects#894
Open
labolado wants to merge 1 commit intocoronalabs:masterfrom
Open
Fix physics use-after-free crash for offscreen display objects#894labolado wants to merge 1 commit intocoronalabs:masterfrom
labolado wants to merge 1 commit intocoronalabs:masterfrom
Conversation
~DisplayObjectExtensions previously checked GetParent() before clearing b2Body userData. GetParent() returns NULL for objects with IsRenderedOffScreen flag (snapshot.group, canvas texture cache groups), causing SetUserData(NULL) to be skipped. This leaves dangling pointers in the Box2D world body list, which StepWorld dereferences on the next frame, causing SIGSEGV. The fix removes the parent dependency and unconditionally clears userData. This is safe because SetUserData(NULL) has no side effects and the body is lazily destroyed by StepWorld when it finds NULL userData.
Contributor
|
Hi, just curious, is it 6 FPS during testing or just a typo? Thanks. ...
if frame >= 360 then
print("PASS: 60 seconds without crash")
os.exit(0)
end
... |
Author
|
Good catch — that was leftover test infrastructure. Updated the PR with a clean minimal reproduction (7 lines for macOS + MallocScribble, full test for iOS). |
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.
Summary
Fix SIGSEGV crash in
PhysicsWorld::StepWorld()when physics bodies are used with offscreen display objects (snapshot groups, canvas texture caches).Problem
~DisplayObjectExtensionschecksGetParent()before clearingb2Body::SetUserData(NULL). For objects withIsRenderedOffScreen=true,GetParent()always returns NULL, soSetUserData(NULL)is skipped. This leaves dangling pointers in the Box2D body list.Fix
Unconditionally call
fBody->SetUserData(NULL). Safe because it has no side effects — the body is lazily destroyed by StepWorld when it finds NULL userData.Reproduction
macOS (deterministic, instant crash)
Run with
MallocScribble=1:iOS (deterministic, crashes within seconds)
On iOS, freed memory must be overwritten by new allocations. The test creates dangling pointers via the same
snapshot.grouppattern, plus light memory churn (small canvas textures + display objects) to force page reuse:Verified Results