From: Thomas Geymayer Date: Mon, 21 Jul 2014 21:56:41 +0000 (+0200) Subject: canvas::Layout: clear parent/canvas after calling onRemove. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=23413b47818b042620eeeaf306ffe6d1ae81852d;p=simgear.git canvas::Layout: clear parent/canvas after calling onRemove. --- diff --git a/simgear/canvas/layout/BoxLayout.cxx b/simgear/canvas/layout/BoxLayout.cxx index c7a5f123..ec2aee53 100644 --- a/simgear/canvas/layout/BoxLayout.cxx +++ b/simgear/canvas/layout/BoxLayout.cxx @@ -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(); diff --git a/simgear/canvas/layout/LayoutItem.cxx b/simgear/canvas/layout/LayoutItem.cxx index 3abb55a0..a6e30dfb 100644 --- a/simgear/canvas/layout/LayoutItem.cxx +++ b/simgear/canvas/layout/LayoutItem.cxx @@ -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()); }