]> git.mxchange.org Git - simgear.git/commitdiff
canvas::Layout: clear parent/canvas after calling onRemove.
authorThomas Geymayer <tomgey@gmail.com>
Mon, 21 Jul 2014 21:56:41 +0000 (23:56 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 21 Jul 2014 21:56:41 +0000 (23:56 +0200)
simgear/canvas/layout/BoxLayout.cxx
simgear/canvas/layout/LayoutItem.cxx

index c7a5f123b9249b97a22c99c52ab6c0e5ca1a481d..ec2aee530b558f7024dd5669f833f928b13dc4cf 100644 (file)
@@ -125,8 +125,8 @@ namespace canvas
 
     LayoutItems::iterator it = _layout_items.begin() + index;
     LayoutItemRef item = it->layout_item;
-    item->setParent(LayoutItemWeakRef());
     item->onRemove();
+    item->setParent(LayoutItemWeakRef());
     _layout_items.erase(it);
 
     invalidate();
@@ -141,8 +141,8 @@ namespace canvas
                                it != _layout_items.end();
                              ++it )
     {
-      it->layout_item->setParent(LayoutItemWeakRef());
       it->layout_item->onRemove();
+      it->layout_item->setParent(LayoutItemWeakRef());
     }
     _layout_items.clear();
     invalidate();
index 3abb55a0b6d0bee5319d70809a6875245a986d61..a6e30dfbea8a8b6ffb523d25d6d41cd5973fc352 100644 (file)
@@ -163,7 +163,12 @@ namespace canvas
   {
     _parent = parent;
     LayoutItemRef parent_ref = parent.lock();
-    setCanvas(parent_ref ? parent_ref->_canvas : CanvasWeakPtr());
+
+    if( parent_ref )
+      // Only change the canvas if there is a new parent. If the item is removed
+      // keep the old canvas, as it may be used for example during the call to
+      // onRemove.
+      setCanvas(parent_ref->_canvas);
 
     setVisibleInternal(!parent_ref || parent_ref->isVisible());
   }