summaryrefslogtreecommitdiffstats
path: root/src/core/nodes/qnode_p.h
diff options
context:
space:
mode:
authorJim Albamont <jim.albamont@kdab.com>2019-04-04 13:12:30 -0500
committerJames Turner <james.turner@kdab.com>2019-04-08 08:07:49 +0000
commit985a61921fbcb893b89b8dde6eeaab5cf8c5dc1c (patch)
tree803306dfa93f67e1bd047ec09c93b0770cead878 /src/core/nodes/qnode_p.h
parentbf2c2e9bb2dd0b13cb2cb6728de0c2421fbafbb7 (diff)
Fix backend node creation order using an initialization queue
Backend nodes should always be created from the top-most parent down ensuring that every parent is created before its children. The original way of creating backend nodes by calling _q_postConstructorInit in a deferred manner from the QNode constructor breaks this because backend node creation happens in the order that the nodes on the front-end were created. This was often incorrect when reparenting newly created nodes. Fix by creating a queue of nodes needing a _q_postConstructorInit call and only adding nodes to the queue if one of their ancestors is not already in the queue. This ensures that _q_postConstructorInit is only called for the top-most node in any subtree. This behavior exactly matches the creation behavior when building a subtree and reparenting it to a node with a backend. Doing silly things like creating a node with a parent that has a backend then immediately reparenting is now safe. After this patch, it should be safe to assume that backend nodes can always find their backend parent. Adding only the top-most nodes to the queue and processing the entire queue at one time also ensures that all creation events get sent in the same batch. This fixes the problem of having backend nodes referring to other backend nodes that haven't been created yet. Task-number: QTBUG-74106 Task-number: QTBUG-73905 Change-Id: Idcf38d6c3164f6be4394a3b25554547414061059 Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
Diffstat (limited to 'src/core/nodes/qnode_p.h')
-rw-r--r--src/core/nodes/qnode_p.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/core/nodes/qnode_p.h b/src/core/nodes/qnode_p.h
index 6ffb19ce8..8b43c2695 100644
--- a/src/core/nodes/qnode_p.h
+++ b/src/core/nodes/qnode_p.h
@@ -60,6 +60,7 @@
#include <Qt3DCore/private/qobservableinterface_p.h>
#include <Qt3DCore/private/qt3dcore_global_p.h>
#include <QtCore/private/qobject_p.h>
+#include <QQueue>
QT_BEGIN_NAMESPACE
@@ -174,6 +175,23 @@ private:
QHash<QNode *, QMetaObject::Connection> m_destructionConnections;
};
+class NodePostConstructorInit : public QObject
+{
+ Q_OBJECT
+public:
+ NodePostConstructorInit(QObject *parent = nullptr);
+ virtual ~NodePostConstructorInit();
+ void removeNode(QNode *node);
+ void addNode(QNode *node);
+
+private Q_SLOTS:
+ void processNodes();
+
+private:
+ QQueue<QNodePrivate *> m_nodesToConstruct;
+ bool m_requestedProcessing;
+};
+
} // namespace Qt3DCore
QT_END_NAMESPACE