Fix crash in Jolt Physics when switching scenes in editor
Co-authored-by: Jorrit Rouwe <jrouwe@gmail.com>
This commit is contained in:
parent
efb40c1524
commit
e2985a2e1f
3 changed files with 12 additions and 2 deletions
|
|
@ -436,6 +436,12 @@ void JoltSpace3D::remove_object(const JPH::BodyID &p_jolt_id) {
|
|||
}
|
||||
|
||||
body_iface.DestroyBody(p_jolt_id);
|
||||
|
||||
// If we're never going to step this space, like in the editor viewport, we need to manually clean up Jolt's broad phase instead, otherwise performance can degrade when doing things like switching scenes.
|
||||
// We'll never actually have zero bodies in any space though, since we always have the default area, so we check if there's one or fewer left instead.
|
||||
if (!JoltPhysicsServer3D::get_singleton()->is_active() && physics_system->GetNumBodies() <= 1) {
|
||||
physics_system->OptimizeBroadPhase();
|
||||
}
|
||||
}
|
||||
|
||||
void JoltSpace3D::flush_pending_objects() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue