This commit is contained in:
Raphael 2024-02-03 23:31:13 +00:00 committed by GitHub
commit 102aad7d3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 13 deletions

View File

@ -771,6 +771,10 @@ void JoltPhysicsEnvironment::Simulate( float deltaTime )
// doing the simulation...
m_ContactListener.PostSimulationFrame();
// RaphaelIT7: We need to delete all dead objects after m_ContactListener.PostSimulationFrame, or else Jolt freaks out for some reason.
// This also needs to be before pController->OnPreSimulate or else we get some crashes.
DeleteDeadObjects( true );
// Run pre-simulation controllers
for ( IJoltPhysicsController *pController : m_pPhysicsControllers )
pController->OnPreSimulate( deltaTime );
@ -818,8 +822,10 @@ void JoltPhysicsEnvironment::Simulate( float deltaTime )
// If the delete queue is disabled, we only added to it during the simulation
// ie. callbacks etc. So flush that now.
if ( !m_bEnableDeleteQueue )
if ( !m_bEnableDeleteQueue ) {
DeleteDeadObjects();
DeleteDeadObjects( true ); // Also delete all bodies
}
#ifdef JPH_DEBUG_RENDERER
JoltPhysicsDebugRenderer::GetInstance().RenderPhysicsSystem( m_PhysicsSystem );
@ -1430,19 +1436,21 @@ void JoltPhysicsEnvironment::RemoveBodyAndDeleteObject( JoltPhysicsObject *pObje
delete pObject;
}
void JoltPhysicsEnvironment::DeleteDeadObjects()
void JoltPhysicsEnvironment::DeleteDeadObjects( bool delBodies )
{
for ( JoltPhysicsObject *pObject : m_pDeadObjects )
RemoveBodyAndDeleteObject( pObject );
m_pDeadObjects.clear();
if ( delBodies ) {
for ( JoltPhysicsObject *pObject : m_pDeadObjects )
RemoveBodyAndDeleteObject( pObject );
m_pDeadObjects.clear();
} else {
for ( JoltPhysicsConstraint *pConstraint : m_pDeadConstraints )
delete pConstraint;
m_pDeadConstraints.clear();
for ( JoltPhysicsConstraint *pConstraint : m_pDeadConstraints )
delete pConstraint;
m_pDeadConstraints.clear();
for ( CPhysCollide *pCollide : m_pDeadObjectCollides )
JoltPhysicsCollision::GetInstance().DestroyCollide( pCollide );
m_pDeadObjectCollides.clear();
for ( CPhysCollide *pCollide : m_pDeadObjectCollides )
JoltPhysicsCollision::GetInstance().DestroyCollide( pCollide );
m_pDeadObjectCollides.clear();
}
}
//-------------------------------------------------------------------------------------------------

View File

@ -172,7 +172,7 @@ public:
private:
void RemoveBodyAndDeleteObject( JoltPhysicsObject* pObject );
void DeleteDeadObjects();
void DeleteDeadObjects( bool delBodies = false );
template <typename T>
void AddPhysicsSaveRestorePointer( uintp oldPtr, T* newPtr );