Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic caused by despawning entity with ColliderOf #677

Merged
merged 2 commits into from
Mar 24, 2025

Conversation

Jondolf
Copy link
Owner

@Jondolf Jondolf commented Mar 24, 2025

Objective

Fixes #676.

#671 changed the ColliderParent component to a ColliderOf relationship. Because Bevy does not normally allow relationships to point to their own entities, this required a partial manual implementation of the Relationship trait. However, I left the default on_replace implementation, which (as it turns out) panics if the target entity does not exist, which is possible when despawning an entity and the relationship points to itself.

Solution

Manually implement on_replace in a non-panicking way. Also replace some panicking uses of remove with try_remove.

Ideally this would be fixed by Bevy allowing self-relationships though.

@Jondolf Jondolf added C-Bug Something isn't working A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality P-Crash A sudden unexpected crash labels Mar 24, 2025
Copy link

@alec-deason alec-deason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I can verify this fixes both my minimal case and the more complex case it was derived from.

@Jondolf Jondolf merged commit 325030e into main Mar 24, 2025
5 checks passed
@Jondolf Jondolf deleted the fix-despawn-panic branch March 24, 2025 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Collision Relates to the broad phase, narrow phase, colliders, or other collision functionality C-Bug Something isn't working P-Crash A sudden unexpected crash
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic caused by StateScoped entities with avian components
2 participants