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()
{
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;
}
}
}
}