Unregister drawable on close instead of throwing if still in use

This commit is contained in:
Georg Hagen
2024-07-14 01:28:49 +02:00
parent 6e565ac40d
commit 8e7b4f602c

View File

@@ -12,8 +12,13 @@ namespace OpenVulkano::Scene
{ {
void Drawable::Close() void Drawable::Close()
{ {
if (!m_nodes.empty()) throw std::runtime_error("Drawable is still being used!!!"); SetScene(nullptr);
m_scene = nullptr; for (auto& node : m_nodes)
{ // unregister from nodes
Utils::Remove(node->drawables, this);
}
m_nodes.clear();
m_shader = nullptr;
} }
void Drawable::SetScene(Scene* scene) void Drawable::SetScene(Scene* scene)
@@ -23,7 +28,7 @@ namespace OpenVulkano::Scene
const auto oldScene = m_scene; const auto oldScene = m_scene;
m_scene = scene; m_scene = scene;
if (scene) scene->RegisterDrawable(this); if (scene) scene->RegisterDrawable(this);
else if (oldScene) oldScene->RemoveDrawable(this); if (oldScene) oldScene->RemoveDrawable(this);
} }
void Drawable::AddNode(Node* node) void Drawable::AddNode(Node* node)
@@ -41,4 +46,4 @@ namespace OpenVulkano::Scene
m_scene = nullptr; m_scene = nullptr;
} }
} }
} }