From 839f0dfe65cff569939dcd277aa7590410d7c066 Mon Sep 17 00:00:00 2001 From: Evgeny Prikazchikov Date: Sun, 19 Jul 2026 17:21:14 +0300 Subject: [PATCH] Engine: Deletion of actor can bring to crash #1375 --- engine/includes/components/component.h | 1 + engine/src/components/actor.cpp | 16 ++++++++++++++-- engine/src/components/component.cpp | 6 ++++++ .../scenecomposer/actions/deleteobjects.cpp | 6 +++--- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/engine/includes/components/component.h b/engine/includes/components/component.h index 5f8834722..f7be1d132 100644 --- a/engine/includes/components/component.h +++ b/engine/includes/components/component.h @@ -68,6 +68,7 @@ class ENGINE_EXPORT Component : public Object { bool hasTag(const TString &tag); bool hasTagByHash(uint32_t hash); + const std::vector &tags() const; virtual void composeComponent(); diff --git a/engine/src/components/actor.cpp b/engine/src/components/actor.cpp index 760c4f5c2..dd8aaad99 100644 --- a/engine/src/components/actor.cpp +++ b/engine/src/components/actor.cpp @@ -67,8 +67,20 @@ Actor::Actor() : } Actor::~Actor() { - if(m_scene && m_scene->world()) { - m_scene->world()->graphUpdated(); + if(m_scene) { + World *world = m_scene->world(); + if(world) { + world->graphUpdated(); + } + + for(auto it : getChildren()) { + Component *component = dynamic_cast(it); + if(component) { + for(uint32_t it : component->tags()) { + m_scene->removeFromGroupByHash(component, it); + } + } + } } } /*! diff --git a/engine/src/components/component.cpp b/engine/src/components/component.cpp index bf9273f17..d96f5907e 100644 --- a/engine/src/components/component.cpp +++ b/engine/src/components/component.cpp @@ -188,6 +188,12 @@ bool Component::hasTag(const TString &tag) { bool Component::hasTagByHash(uint32_t hash) { return std::find(m_tags.begin(), m_tags.end(), hash) != m_tags.end(); } +/*! + Returns list of component tags. +*/ +const std::vector &Component::tags() const { + return m_tags; +} /*! \internal */ diff --git a/worldeditor/src/screens/scenecomposer/actions/deleteobjects.cpp b/worldeditor/src/screens/scenecomposer/actions/deleteobjects.cpp index 3741c8414..00e1afc89 100644 --- a/worldeditor/src/screens/scenecomposer/actions/deleteobjects.cpp +++ b/worldeditor/src/screens/scenecomposer/actions/deleteobjects.cpp @@ -121,6 +121,9 @@ void DeleteObjects::redo() { } } + m_controller->clear(); + m_controller->selectActors(list); + for(auto it : m_objects) { Object *object = Engine::findObject(it); if(object) { @@ -128,9 +131,6 @@ void DeleteObjects::redo() { } } - m_controller->clear(); - m_controller->selectActors(list); - for(auto it : scenes) { emit m_controller->sceneUpdated(it); }