diff options
author | Kim Motoyoshi Kalland <kim.kalland@nokia.com> | 2011-08-12 13:25:27 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-12 14:02:44 +0200 |
commit | 882831e39e882ea4a7f7b3e6ea719b969951778f (patch) | |
tree | f0878413d2c7076a7ffc3b17f6cb8e83b6e0c5a9 | |
parent | 313ebbea192dae510db59b506e98b88734f3885b (diff) |
Fixed QSGNode leak.
QSGItem was setting its node pointer to 0 without deleting it.
Change-Id: I8b52d02069410b1dfc0057f926a52c946ef348a2
Reviewed-on: http://codereview.qt.nokia.com/2910
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
-rw-r--r-- | src/declarative/items/qsgcanvas.cpp | 2 | ||||
-rw-r--r-- | src/declarative/items/qsgitem.cpp | 36 | ||||
-rw-r--r-- | src/declarative/scenegraph/coreapi/qsgnode.cpp | 2 |
3 files changed, 32 insertions, 8 deletions
diff --git a/src/declarative/items/qsgcanvas.cpp b/src/declarative/items/qsgcanvas.cpp index 03b6a72b96..b579cc7236 100644 --- a/src/declarative/items/qsgcanvas.cpp +++ b/src/declarative/items/qsgcanvas.cpp @@ -910,12 +910,10 @@ QSGCanvas::~QSGCanvas() // manually cleanup for the root item (item destructor only handles these when an item is parented) QSGItemPrivate *rootItemPrivate = QSGItemPrivate::get(d->rootItem); rootItemPrivate->removeFromDirtyList(); - rootItemPrivate->canvas = 0; delete d->rootItem; d->rootItem = 0; d->cleanupNodes(); - if (!d->contextFailed) { // We need to remove all references to textures pointing to "our" QSGContext // from the QDeclarativePixmapCache. Call into the cache to remove the GL / Scene Graph diff --git a/src/declarative/items/qsgitem.cpp b/src/declarative/items/qsgitem.cpp index 2298be1341..c2abc46ab9 100644 --- a/src/declarative/items/qsgitem.cpp +++ b/src/declarative/items/qsgitem.cpp @@ -1718,15 +1718,34 @@ QSGItem::QSGItem(QSGItemPrivate &dd, QSGItem *parent) d->init(parent); } +#ifndef QT_NO_DEBUG +static int qt_item_count = 0; + +static void qt_print_item_count() +{ + qDebug("Number of leaked items: %i", qt_item_count); + qt_item_count = -1; +} +#endif + /*! Destroys the QSGItem. */ QSGItem::~QSGItem() { +#ifndef QT_NO_DEBUG + --qt_item_count; + if (qt_item_count < 0) + qDebug("Item destroyed after qt_print_item_count() was called."); +#endif + Q_D(QSGItem); + if (d->parentItem) + setParentItem(0); + else if (d->canvas && d->itemNodeInstance) + QSGCanvasPrivate::get(d->canvas)->cleanup(d->itemNodeInstance); // cleanup root // XXX todo - optimize - setParentItem(0); while (!d->childItems.isEmpty()) d->childItems.first()->setParentItem(0); @@ -1824,9 +1843,6 @@ void QSGItem::setParentItem(QSGItem *parentItem) QSGCanvas *parentCanvas = parentItem?QSGItemPrivate::get(parentItem)->canvas:0; if (d->canvas != parentCanvas) { - if (d->canvas && d->itemNodeInstance) - QSGCanvasPrivate::get(d->canvas)->cleanup(d->itemNodeInstance); - QSGItemPrivate::InitializationState initState; initState.clear(); d->initCanvas(&initState, parentCanvas); @@ -2021,6 +2037,8 @@ void QSGItemPrivate::initCanvas(InitializationState *state, QSGCanvas *c) c->mouseGrabberItem = 0; if ( hoverEnabled ) c->hoverItems.removeAll(q); + if (itemNodeInstance) + c->cleanup(itemNodeInstance); } canvas = c; @@ -2031,7 +2049,6 @@ void QSGItemPrivate::initCanvas(InitializationState *state, QSGCanvas *c) if (canvas && hoverEnabled && !canvas->hasMouseTracking()) canvas->setMouseTracking(true); - // XXX todo - why aren't these added to the destroy list? itemNodeInstance = 0; opacityNode = 0; clipNode = 0; @@ -2198,6 +2215,15 @@ QSGItemPrivate::QSGItemPrivate() void QSGItemPrivate::init(QSGItem *parent) { +#ifndef QT_NO_DEBUG + ++qt_item_count; + static bool atexit_registered = false; + if (!atexit_registered) { + atexit(qt_print_item_count); + atexit_registered = true; + } +#endif + Q_Q(QSGItem); baselineOffset.invalidate(); diff --git a/src/declarative/scenegraph/coreapi/qsgnode.cpp b/src/declarative/scenegraph/coreapi/qsgnode.cpp index 4779b00406..bff289b332 100644 --- a/src/declarative/scenegraph/coreapi/qsgnode.cpp +++ b/src/declarative/scenegraph/coreapi/qsgnode.cpp @@ -126,7 +126,7 @@ QSGNode::~QSGNode() #ifndef QT_NO_DEBUG --qt_node_count; if (qt_node_count < 0) - qDebug("Material destroyed after qt_print_node_count() was called."); + qDebug("Node destroyed after qt_print_node_count() was called."); #endif destroy(); } |