summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2020-10-01 10:22:47 +0100
committerSean Harmer <sean.harmer@kdab.com>2020-10-01 11:49:25 +0100
commit0a533673b5450d49725d23e08ac13b03fad564fb (patch)
tree818427262fcc32554bf33e5805610676e6cdc279 /src
parent5a4a8e4f6644bc1d1cbfb1b0c96b096d6d4a9a5a (diff)
Fix a crash when node is added and destroyed immediately
When a node is added to the scene it is scheduled for a post-creation initialization. However, if the node is destroyed before this post-creation queue has been processed we will crash. This commit ensures that the node being deleted is removed from the post-creation queue. Usually the queue will be empty and so this should not add a performance penalty. Pick-to: 5.15 Change-Id: Ibe4289e1e54cdb145f8588f15dc4ad894e427582 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/nodes/qnode.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/core/nodes/qnode.cpp b/src/core/nodes/qnode.cpp
index 15a2f5978..baf9525cb 100644
--- a/src/core/nodes/qnode.cpp
+++ b/src/core/nodes/qnode.cpp
@@ -134,6 +134,11 @@ void QNodePrivate::notifyDestructionChangesAndRemoveFromScene()
{
Q_Q(QNode);
+ // Ensure this node is not queued up for post-construction init
+ // to avoid crashing when the event loop spins.
+ if (m_scene && m_scene->postConstructorInit())
+ m_scene->postConstructorInit()->removeNode(q);
+
// Tell the backend we are about to be destroyed
if (m_hasBackendNode && m_scene && m_scene->engine())
QAspectEnginePrivate::get(m_scene->engine())->removeNode(q);