summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAurélien Brooke <aurelien@bahiasoft.fr>2022-12-01 09:03:30 +0100
committerAurélien Brooke <aurelien@bahiasoft.fr>2022-12-17 08:15:03 +0100
commitbe8b6796c17cd1a616975bbd24f7a0cead725a48 (patch)
tree44c11fc2dbf325ac5123cfd8430ffc19fd7a832f /src
parentbffdaabaa5cd9d7fdc64e4124817b504319708e1 (diff)
LoadSceneJob: don't risk to leak the loaded subtree
There is a risk that the front-end QSceneLoader node has been destroyed by the time the LoadSceneJob completes. The postFrame() would then do nothing, and the m_sceneSubtree pointer will be forgotten, leaking the whole tree. This can happen in real life when loading very large scenes. To ensure that we cannot leak the scene tree, use strict pointer ownership with std::unique_ptr. Pick-to: 6.4 6.5 Change-Id: Ie2281bc178fc8793bab967a13ea8d30aa46268a0 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/render/jobs/loadscenejob.cpp4
-rw-r--r--src/render/jobs/loadscenejob_p.h3
2 files changed, 4 insertions, 3 deletions
diff --git a/src/render/jobs/loadscenejob.cpp b/src/render/jobs/loadscenejob.cpp
index 52b16b041..eca057723 100644
--- a/src/render/jobs/loadscenejob.cpp
+++ b/src/render/jobs/loadscenejob.cpp
@@ -104,7 +104,7 @@ void LoadSceneJob::run()
}
Q_D(LoadSceneJob);
- d->m_sceneSubtree = sceneSubTree;
+ d->m_sceneSubtree = std::unique_ptr<Qt3DCore::QEntity>(sceneSubTree);
d->m_status = finalStatus;
if (d->m_sceneSubtree) {
@@ -161,7 +161,7 @@ void LoadSceneJobPrivate::postFrame(Qt3DCore::QAspectManager *manager)
// any subtree it may hold
// Set clone of sceneTree in sceneComponent. This will move the sceneSubTree
// to the QCoreApplication thread which is where the frontend object tree lives.
- dNode->setSceneRoot(m_sceneSubtree);
+ dNode->setSceneRoot(m_sceneSubtree.release());
// Note: the status is set after the subtree so that bindinds depending on the status
// in the frontend will be consistent
diff --git a/src/render/jobs/loadscenejob_p.h b/src/render/jobs/loadscenejob_p.h
index 85282a21e..47287e109 100644
--- a/src/render/jobs/loadscenejob_p.h
+++ b/src/render/jobs/loadscenejob_p.h
@@ -16,6 +16,7 @@
//
#include <Qt3DCore/qaspectjob.h>
+#include <Qt3DCore/qentity.h>
#include <Qt3DCore/private/qaspectjob_p.h>
#include <Qt3DCore/qnodeid.h>
#include <Qt3DRender/qsceneloader.h>
@@ -45,7 +46,7 @@ public:
void postFrame(Qt3DCore::QAspectManager *manager) override;
- Qt3DCore::QEntity *m_sceneSubtree = nullptr;
+ std::unique_ptr<Qt3DCore::QEntity> m_sceneSubtree;
QSceneLoader::Status m_status = QSceneLoader::None;
Q_DECLARE_PUBLIC(LoadSceneJob)