1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #108239 from mihe/jolt/scene-switch-crash

Fix crash in Jolt Physics when switching scenes in editor
This commit is contained in:
Thaddeus Crews
2025-07-04 10:09:05 -05:00
3 changed files with 12 additions and 2 deletions

View File

@@ -73,6 +73,7 @@ void BroadPhaseQuadTree::Optimize()
{
JPH_PROFILE_FUNCTION();
// Free the previous tree so we can create a new optimized tree
FrameSync();
LockModifications();
@@ -80,7 +81,7 @@ void BroadPhaseQuadTree::Optimize()
for (uint l = 0; l < mNumLayers; ++l)
{
QuadTree &tree = mLayers[l];
if (tree.HasBodies())
if (tree.HasBodies() || tree.IsDirty())
{
QuadTree::UpdateState update_state;
tree.UpdatePrepare(mBodyManager->GetBodies(), mTracking, update_state, true);
@@ -90,6 +91,9 @@ void BroadPhaseQuadTree::Optimize()
UnlockModifications();
// Free the tree from before we created a new optimized tree
FrameSync();
mNextLayerToUpdate = 0;
}

View File

@@ -301,7 +301,7 @@ void QuadTree::UpdatePrepare(const BodyVector &inBodies, TrackingVector &ioTrack
#endif
// Create space for all body ID's
NodeID *node_ids = new NodeID [mNumBodies];
NodeID *node_ids = mNumBodies > 0? new NodeID [mNumBodies] : nullptr;
NodeID *cur_node_id = node_ids;
// Collect all bodies