JoltPhysics3D: Fix destruction of just created bodies

This commit is contained in:
SirLynix 2023-08-04 12:27:26 +02:00
parent 62adfdd26c
commit e6f26f04a9
1 changed files with 8 additions and 8 deletions

View File

@ -496,6 +496,13 @@ namespace Nz
void JoltPhysWorld3D::UnregisterBody(const JPH::BodyID& bodyID, bool destroy, bool removeFromActivationList)
{
// Remove from list first as bodyID may be invalidated by destruction
if (removeFromActivationList)
{
m_world->pendingAdditionActivate.erase(bodyID);
m_world->pendingAdditionNoActivate.erase(bodyID);
}
if (destroy)
{
auto& bodyInterface = m_world->physicsSystem.GetBodyInterface();
@ -511,17 +518,10 @@ namespace Nz
bodyInterface.RemoveBody(bodyID);
}
bodyInterface.DestroyBody(bodyID);
bodyInterface.DestroyBody(bodyID); //< this invalidate the bodyID reference!
}
else
m_world->pendingDeactivations.insert(bodyID);
if (removeFromActivationList)
{
m_world->pendingAdditionActivate.erase(bodyID);
m_world->pendingAdditionNoActivate.erase(bodyID);
}
}
std::shared_ptr<JoltCharacterImpl> JoltPhysWorld3D::GetDefaultCharacterImpl()