Correctly deinitialize scenegraph nodes that are added at runtime

This commit is contained in:
Alexander Bock
2023-01-21 16:52:14 +01:00
parent db375318d8
commit 59a8a006ee
3 changed files with 12 additions and 26 deletions

View File

@@ -84,12 +84,6 @@ public:
Scene(std::unique_ptr<SceneInitializer> 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
*/

View File

@@ -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> sceneInitializer;
if (global::configuration->useMultithreadedInitialization) {
unsigned int nAvailableThreads = std::min(

View File

@@ -108,7 +108,18 @@ Scene::Scene(std::unique_ptr<SceneInitializer> 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<std::string, SceneGraphNode*>& Scene::nodesByIdentifier() const {
return _nodesByIdentifier;
}