Adjusted for new component removal method

This commit is contained in:
Diren D Bharwani 2022-11-01 14:46:56 +08:00
parent 8139cc78b2
commit 35771a619a
1 changed files with 11 additions and 13 deletions

View File

@ -630,10 +630,6 @@ namespace SHADE
auto* rigidBodyComponent = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(ENTITY_ID);
auto* colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(ENTITY_ID);
SHASSERT(physicsObject != nullptr, "Physics object " + std::to_string(ENTITY_ID) + " has been lost from the world!")
if (REMOVED_ID == RIGID_BODY_ID)
{
// Wake up all physics objects
for (auto& [entityID, object] : map)
{
@ -641,6 +637,8 @@ namespace SHADE
reinterpret_cast<rp3d::RigidBody*>(object.rp3dBody)->setIsSleeping(false);
}
if (REMOVED_ID == RIGID_BODY_ID && physicsObject != nullptr)
{
world->destroyRigidBody(reinterpret_cast<rp3d::RigidBody*>(physicsObject->rp3dBody));
physicsObject->rp3dBody = nullptr;
@ -657,7 +655,7 @@ namespace SHADE
}
}
if (REMOVED_ID == COLLIDER_ID)
if (REMOVED_ID == COLLIDER_ID && physicsObject != nullptr)
{
// Remove all colliders
const int NUM_COLLIDERS = static_cast<int>(physicsObject->rp3dBody->getNbColliders());
@ -673,7 +671,7 @@ namespace SHADE
physicsObject->rp3dBody = nullptr;
}
if (physicsObject->rp3dBody == nullptr)
if (physicsObject != nullptr && physicsObject->rp3dBody == nullptr)
DestroyPhysicsObject(ENTITY_ID);
}