From 59a8a006ee9d7b2003d78e3dafc1fd52aa4e6d21 Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sat, 21 Jan 2023 16:52:14 +0100 Subject: [PATCH] Correctly deinitialize scenegraph nodes that are added at runtime --- include/openspace/scene/scene.h | 6 ------ src/engine/openspaceengine.cpp | 14 -------------- src/scene/scene.cpp | 18 ++++++++++++------ 3 files changed, 12 insertions(+), 26 deletions(-) diff --git a/include/openspace/scene/scene.h b/include/openspace/scene/scene.h index 69907001e1..7a50b37c93 100644 --- a/include/openspace/scene/scene.h +++ b/include/openspace/scene/scene.h @@ -84,12 +84,6 @@ public: Scene(std::unique_ptr initializer); virtual ~Scene() override; - /** - * Clear the scene graph, - * i.e. set the root node to nullptr and deallocate all scene graph nodes. - */ - void clear(); - /** * Attach node to the root */ diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index 1611ca1f6b..86fbc15cd2 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -685,20 +685,6 @@ void OpenSpaceEngine::loadAssets() { global::windowDelegate->setBarrier(true); }; - if (_scene) { - ZoneScopedN("Reset scene") - - global::syncEngine->removeSyncables(global::timeManager->syncables()); - if (_scene && _scene->camera()) { - global::syncEngine->removeSyncables(_scene->camera()->syncables()); - } - global::renderEngine->setScene(nullptr); - global::renderEngine->setCamera(nullptr); - global::navigationHandler->setCamera(nullptr); - _scene->clear(); - global::rootPropertyOwner->removePropertySubOwner(_scene.get()); - } - std::unique_ptr sceneInitializer; if (global::configuration->useMultithreadedInitialization) { unsigned int nAvailableThreads = std::min( diff --git a/src/scene/scene.cpp b/src/scene/scene.cpp index 5cc0bb8d02..46fa8a94e2 100644 --- a/src/scene/scene.cpp +++ b/src/scene/scene.cpp @@ -108,7 +108,18 @@ Scene::Scene(std::unique_ptr initializer) } Scene::~Scene() { - clear(); + LINFO("Clearing current scene graph"); + for (SceneGraphNode* node : _topologicallySortedNodes) { + if (node->identifier() == "Root") { + continue; + } + // There might still be scene graph nodes around that weren't removed by the asset + // manager as they would have been added manually by the user. This also serves as + // a backstop for assets that forgot to implement the onDeinitialize functions + node->deinitializeGL(); + node->deinitialize(); + } + _rootDummy.clearChildren(); _rootDummy.setScene(nullptr); } @@ -309,11 +320,6 @@ void Scene::render(const RenderData& data, RendererTasks& tasks) { } } -void Scene::clear() { - LINFO("Clearing current scene graph"); - _rootDummy.clearChildren(); -} - const std::unordered_map& Scene::nodesByIdentifier() const { return _nodesByIdentifier; }