From 8e7b4f602c1f21c939de39bce524ca94584c64cf Mon Sep 17 00:00:00 2001 From: Georg Hagen Date: Sun, 14 Jul 2024 01:28:49 +0200 Subject: [PATCH] Unregister drawable on close instead of throwing if still in use --- openVulkanoCpp/Scene/Drawable.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openVulkanoCpp/Scene/Drawable.cpp b/openVulkanoCpp/Scene/Drawable.cpp index c8e6e22..4fa280f 100644 --- a/openVulkanoCpp/Scene/Drawable.cpp +++ b/openVulkanoCpp/Scene/Drawable.cpp @@ -12,8 +12,13 @@ namespace OpenVulkano::Scene { void Drawable::Close() { - if (!m_nodes.empty()) throw std::runtime_error("Drawable is still being used!!!"); - m_scene = nullptr; + SetScene(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) @@ -23,7 +28,7 @@ namespace OpenVulkano::Scene const auto oldScene = m_scene; m_scene = scene; if (scene) scene->RegisterDrawable(this); - else if (oldScene) oldScene->RemoveDrawable(this); + if (oldScene) oldScene->RemoveDrawable(this); } void Drawable::AddNode(Node* node) @@ -41,4 +46,4 @@ namespace OpenVulkano::Scene m_scene = nullptr; } } -} \ No newline at end of file +}