Fixed crashes
This commit is contained in:
@@ -42,10 +42,32 @@ Gizmo::Gizmo(Ogre::SceneManager *sceneMgr)
|
||||
|
||||
Gizmo::~Gizmo()
|
||||
{
|
||||
if (m_axisX) m_sceneMgr->destroyManualObject(m_axisX);
|
||||
if (m_axisY) m_sceneMgr->destroyManualObject(m_axisY);
|
||||
if (m_axisZ) m_sceneMgr->destroyManualObject(m_axisZ);
|
||||
if (m_gizmoNode) m_sceneMgr->destroySceneNode(m_gizmoNode);
|
||||
// Detach objects from node first to avoid double-delete
|
||||
if (m_gizmoNode) {
|
||||
if (m_axisX) m_gizmoNode->detachObject(m_axisX);
|
||||
if (m_axisY) m_gizmoNode->detachObject(m_axisY);
|
||||
if (m_axisZ) m_gizmoNode->detachObject(m_axisZ);
|
||||
}
|
||||
|
||||
// Now destroy the manual objects
|
||||
if (m_axisX) {
|
||||
m_sceneMgr->destroyManualObject(m_axisX);
|
||||
m_axisX = nullptr;
|
||||
}
|
||||
if (m_axisY) {
|
||||
m_sceneMgr->destroyManualObject(m_axisY);
|
||||
m_axisY = nullptr;
|
||||
}
|
||||
if (m_axisZ) {
|
||||
m_sceneMgr->destroyManualObject(m_axisZ);
|
||||
m_axisZ = nullptr;
|
||||
}
|
||||
|
||||
// Finally destroy the node
|
||||
if (m_gizmoNode) {
|
||||
m_sceneMgr->destroySceneNode(m_gizmoNode);
|
||||
m_gizmoNode = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void Gizmo::attachTo(flecs::entity entity)
|
||||
|
||||
@@ -648,6 +648,14 @@ void EditorUISystem::deleteEntity(flecs::entity entity)
|
||||
deleteEntity(child);
|
||||
}
|
||||
|
||||
// Clean up physics body before removing component
|
||||
if (entity.has<RigidBodyComponent>()) {
|
||||
auto &rigidBody = entity.get_mut<RigidBodyComponent>();
|
||||
if (m_physicsSystem && rigidBody.bodyCreated) {
|
||||
m_physicsSystem->removeRigidBody(rigidBody);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up transform node
|
||||
if (entity.has<TransformComponent>()) {
|
||||
auto &transform = entity.get_mut<TransformComponent>();
|
||||
|
||||
@@ -33,6 +33,9 @@ public:
|
||||
|
||||
bool isInitialized() const { return m_initialized; }
|
||||
|
||||
// Remove a rigid body (public for external cleanup)
|
||||
void removeRigidBody(RigidBodyComponent& rigidBody);
|
||||
|
||||
private:
|
||||
// Create a shape from collider component
|
||||
JPH::ShapeRefC createShape(PhysicsColliderComponent& collider);
|
||||
@@ -44,9 +47,6 @@ private:
|
||||
void updateRigidBody(flecs::entity entity, RigidBodyComponent& rigidBody,
|
||||
class TransformComponent& transform);
|
||||
|
||||
// Remove a rigid body
|
||||
void removeRigidBody(RigidBodyComponent& rigidBody);
|
||||
|
||||
flecs::world& m_world;
|
||||
Ogre::SceneManager* m_sceneMgr;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user