Make sure we deref an item from its window.
authorGunnar Sletta <gunnar.sletta@jollamobile.com>
Fri, 6 Mar 2015 10:39:49 +0000 (11:39 +0100)
committerGunnar Sletta <gunnar@sletta.org>
Fri, 6 Mar 2015 10:56:13 +0000 (10:56 +0000)
We should compare against our own window, not our parent's.

The ref/deref logic for items is there to aid us with having "property
var foo: Image { }" in ShaderEffects, where the property is a
parentless member of a given window. The shader effect would ref
all member properties which are used as samplers, giving these items
the same d->window as itself.

As a consequence, it is wrong to check the old parent's window when it
is the item itself that knows which window it is attached to.

Change-Id: Ic34354fd86b52a7334f9757bf408bef0e25ecfd5
Task-number: QTBUG-43376
Reviewed-by: Andrew den Exter <andrew.den.exter@qinetic.com.au>
src/quick/items/qquickitem.cpp

index d1369fb..a37cc34 100644 (file)
@@ -2527,13 +2527,12 @@ void QQuickItem::setParentItem(QQuickItem *parentItem)
         QQuickWindowPrivate::get(d->window)->parentlessItems.remove(this);
     }
 
-    QQuickWindow *oldParentWindow = oldParentItem ? QQuickItemPrivate::get(oldParentItem)->window : 0;
     QQuickWindow *parentWindow = parentItem ? QQuickItemPrivate::get(parentItem)->window : 0;
-    if (oldParentWindow == parentWindow) {
+    if (d->window == parentWindow) {
         // Avoid freeing and reallocating resources if the window stays the same.
         d->parentItem = parentItem;
     } else {
-        if (oldParentWindow)
+        if (d->window)
             d->derefWindow();
         d->parentItem = parentItem;
         if (parentWindow)