diff options
author | Aurélien Brooke <aurelien@bahiasoft.fr> | 2022-12-01 09:03:30 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2022-12-17 08:58:49 +0000 |
commit | d356f4d7660528505574d0adfdba6f48ad332d44 (patch) | |
tree | f39e52cc94db52de26dd9f67c79c63cd96ea2a5c | |
parent | 02ce20c946586e227e6295acb327284d728dd93d (diff) | |
download | qt3d-d356f4d7660528505574d0adfdba6f48ad332d44.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.cpp | 4 | ||||
-rw-r--r-- | src/render/jobs/loadscenejob_p.h | 3 |
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) |