Merge pull request #145 from SHADE-DP/SP3-2-Physics
SP3-2 Remove component bugfix BUGFIX Fixed crash from attempted removal of non-existent rigidbodies / colliders
This commit is contained in:
commit
68237ae086
|
@ -39,13 +39,13 @@ namespace SHADE
|
||||||
if (comp)
|
if (comp)
|
||||||
{
|
{
|
||||||
comp->OnDestroy();
|
comp->OnDestroy();
|
||||||
|
|
||||||
|
SHComponentRemovedEvent eventData;
|
||||||
|
eventData.eid = entityID;
|
||||||
|
eventData.removedComponentType = i;
|
||||||
|
|
||||||
|
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
|
||||||
}
|
}
|
||||||
SHComponentRemovedEvent eventData;
|
|
||||||
eventData.eid = entityID;
|
|
||||||
eventData.removedComponentType = i;
|
|
||||||
|
|
||||||
SHEventManager::BroadcastEvent<SHComponentRemovedEvent>(eventData, SH_COMPONENT_REMOVED_EVENT);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -612,10 +612,17 @@ namespace SHADE
|
||||||
auto* rigidBodyComponent = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(ENTITY_ID);
|
auto* rigidBodyComponent = SHComponentManager::GetComponent_s<SHRigidBodyComponent>(ENTITY_ID);
|
||||||
auto* colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(ENTITY_ID);
|
auto* colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(ENTITY_ID);
|
||||||
|
|
||||||
SHASSERT(physicsObject != nullptr, "Physics object has been lost from the world!")
|
SHASSERT(physicsObject != nullptr, "Physics object " + std::to_string(ENTITY_ID) + " has been lost from the world!")
|
||||||
|
|
||||||
if (REMOVED_ID == RIGID_BODY_ID)
|
if (REMOVED_ID == RIGID_BODY_ID)
|
||||||
{
|
{
|
||||||
|
// Wake up all physics objects
|
||||||
|
for (auto& [entityID, object] : map)
|
||||||
|
{
|
||||||
|
if (SHComponentManager::HasComponent<SHRigidBodyComponent>(entityID))
|
||||||
|
reinterpret_cast<rp3d::RigidBody*>(object.rp3dBody)->setIsSleeping(false);
|
||||||
|
}
|
||||||
|
|
||||||
world->destroyRigidBody(reinterpret_cast<rp3d::RigidBody*>(physicsObject->rp3dBody));
|
world->destroyRigidBody(reinterpret_cast<rp3d::RigidBody*>(physicsObject->rp3dBody));
|
||||||
physicsObject->rp3dBody = nullptr;
|
physicsObject->rp3dBody = nullptr;
|
||||||
|
|
||||||
|
@ -630,13 +637,6 @@ namespace SHADE
|
||||||
for (auto& collider : colliderComponent->colliders)
|
for (auto& collider : colliderComponent->colliders)
|
||||||
physicsObject->AddCollider(&collider);
|
physicsObject->AddCollider(&collider);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wake up all physics objects
|
|
||||||
for (auto& [entityID, object] : map)
|
|
||||||
{
|
|
||||||
if (SHComponentManager::HasComponent<SHRigidBodyComponent>(entityID))
|
|
||||||
reinterpret_cast<rp3d::RigidBody*>(object.rp3dBody)->setIsSleeping(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (REMOVED_ID == COLLIDER_ID)
|
if (REMOVED_ID == COLLIDER_ID)
|
||||||
|
|
Loading…
Reference in New Issue