summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Brooke <aurelien@bahiasoft.fr>2022-12-01 09:03:30 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-12-18 15:18:04 +0000
commit31cfaa743352c01bd08fce46a15ea5ffd2896f13 (patch)
treea12d047a8d9a4afb89f192c664cfc5ee1529f480
parentf52458d825222805bc88348f54a681e41a14b2c3 (diff)
downloadqt3d-31cfaa743352c01bd08fce46a15ea5ffd2896f13.tar.gz
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. Change-Id: Ie2281bc178fc8793bab967a13ea8d30aa46268a0 Reviewed-by: Paul Lemire <paul.lemire@kdab.com> (cherry picked from commit be8b6796c17cd1a616975bbd24f7a0cead725a48) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-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)