From 2329582577aab8ee35f93c193f3584e49eaeba34 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Mon, 20 Jun 2011 10:53:34 +0200 Subject: [PATCH] Removed unnecessary calls to QSGNode::destroy(). --- src/declarative/scenegraph/coreapi/qsgnode.cpp | 18 ++++++++++++------ src/declarative/scenegraph/coreapi/qsgnode.h | 11 +++-------- src/declarative/scenegraph/coreapi/qsgrenderer.cpp | 8 ++++++++ 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/declarative/scenegraph/coreapi/qsgnode.cpp b/src/declarative/scenegraph/coreapi/qsgnode.cpp index fa720a3..bfe17ca 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.cpp +++ b/src/declarative/scenegraph/coreapi/qsgnode.cpp @@ -174,6 +174,17 @@ bool QSGNode::isSubtreeBlocked() const return m_subtreeGeometryCount == 0; } +/*! + \internal + Detaches the node from the scene graph and deletes any children it owns. + + This function is called from QSGNode's and QSGRootNode's destructor. It + should not be called explicitly in user code. QSGRootNode needs to call + destroy() because destroy() calls removeChildNode() which in turn calls + markDirty() which type-casts the node to QSGRootNode. This type-cast is not + valid at the time QSGNode's destructor is called because the node will + already be partially destroyed at that point. +*/ void QSGNode::destroy() { @@ -493,7 +504,6 @@ QSGBasicGeometryNode::QSGBasicGeometryNode(NodeType type) QSGBasicGeometryNode::~QSGBasicGeometryNode() { - destroy(); if (flags() & OwnsGeometry) delete m_geometry; } @@ -569,7 +579,6 @@ QSGGeometryNode::QSGGeometryNode() QSGGeometryNode::~QSGGeometryNode() { - destroy(); if (flags() & OwnsMaterial) delete m_material; if (flags() & OwnsOpaqueMaterial) @@ -731,7 +740,6 @@ QSGClipNode::QSGClipNode() QSGClipNode::~QSGClipNode() { - destroy(); } @@ -807,7 +815,6 @@ QSGTransformNode::QSGTransformNode() QSGTransformNode::~QSGTransformNode() { - destroy(); } @@ -881,7 +888,7 @@ QSGRootNode::~QSGRootNode() { while (!m_renderers.isEmpty()) m_renderers.last()->setRootNode(0); - destroy(); + destroy(); // Must call destroy() here because markDirty() casts this to QSGRootNode. } @@ -940,7 +947,6 @@ QSGOpacityNode::QSGOpacityNode() QSGOpacityNode::~QSGOpacityNode() { - destroy(); } diff --git a/src/declarative/scenegraph/coreapi/qsgnode.h b/src/declarative/scenegraph/coreapi/qsgnode.h index 2705958..cee6b76 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.h +++ b/src/declarative/scenegraph/coreapi/qsgnode.h @@ -152,16 +152,11 @@ public: protected: QSGNode(NodeType type); - // When a node is destroyed, it will detach from the scene graph and the renderer will be - // notified about the change. If the node is detached in the base node's destructor, the - // renderer can't safely cast the node to its original type, since at this point it has been - // partly destroyed already. To solve this problem, all the node destructors must call a common - // destroy method. - - void destroy(); - private: + friend class QSGRootNode; + void init(); + void destroy(); QSGNode *m_parent; NodeType m_type; diff --git a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp index f56bf9a..48c34d3 100644 --- a/src/declarative/scenegraph/coreapi/qsgrenderer.cpp +++ b/src/declarative/scenegraph/coreapi/qsgrenderer.cpp @@ -293,6 +293,14 @@ void QSGRenderer::setClearColor(const QColor &color) m_clear_color = color; } +/*! + Updates internal data structures and emits the sceneGraphChanged() signal. + + If \a flags contains the QSGNode::DirtyNodeRemoved flag, the node might be + in the process of being destroyed. It is then not safe to downcast the node + pointer. +*/ + void QSGRenderer::nodeChanged(QSGNode *node, QSGNode::DirtyFlags flags) { Q_UNUSED(node); -- 1.7.2.5