Skip to content

Fix crash when a physical component is removed from its own collision….. - #869

Closed
Paaanaaamaaa wants to merge 7 commits into
Overload-Technologies:mainfrom
Paaanaaamaaa:fix/physical-component-removal-in-callback
Closed

Paaanaaamaaa wants to merge 7 commits into
Overload-Technologies:mainfrom
Paaanaaamaaa:fix/physical-component-removal-in-callback

Conversation

@Paaanaaamaaa

@Paaanaaamaaa Paaanaaamaaa commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes a crash caused by scripts removing an actor's physical component directly inside a collision or trigger callback

Cause: The callback fires mid-step inside Bullet's stepSimulation and Event::Invoke. Actor::RemoveComponent was deleting the component immediately on the spot. This tore down its PhysicalObject, its Bullet body, and the active event iterator while Bullet was still actively referencing them. In the editor, there was a second crash: the Inspector tried to draw another frame of widgets bound to the destroyed component because its UI refresh was delayed by a frame.

Fix:

  • PhysicsEngine now tracks when it's actively dispatching (IsDispatching()) and queues items for deferred destruction (DeferDestruction()), which gets flushed at the start of the next Update() and in the destructor.
  • Actor::RemoveComponent detaches the component from the actor right away. If it's a CPhysicalObject and physics is currently dispatching, a new private helper (Actor::ReleaseRemovedComponent) keeps it alive until the next flush.
  • CPhysicalObject::MarkForRemoval() stops pending components from forwarding subsequent collision/trigger events to scripts.
  • The Inspector's ComponentRemovedEvent listener now refreshes in the same frame (DelayAction(..., 0)), preventing it from drawing widgets for dead components.
  • Added defensive guards to Scene::DestroyActor and Scene::CollectGarbages to stop them from running during physics dispatches.

Related Issue(s)

Fixes #866

Review Guidance

  • The component detaches from the actor immediately . Its Bullet body gets cleaned up at the start of the next physics update, and any intermediate events are suppressed in the meantime. The colliding object won't receive an OnCollisionExit for the removed component.

Screenshots/GIFs

N/A

AI Usage Disclosure

NA

Checklist

  • My code follows the project's code style guidelines
  • When applicable, I have commented my code, particularly in hard-to-understand areas
  • When applicable, I have updated the documentation accordingly
  • My changes don't generate new warnings or errors
  • I have reviewed and take responsibility for all code in this PR (including any AI-assisted contributions)

@Paaanaaamaaa Paaanaaamaaa closed this by deleting the head repository Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Crash when a physical component is removed from its own collision or trigger event

1 participant