From 09ac319e87ff8a8e747ef7b5d09e9ecac0276230 Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Tue, 18 Sep 2012 23:21:50 +0200 Subject: [PATCH] Canvas: Don't crash on removing child hierarchie from map Currently if a SGPropertyNode is removed from the property tree only for this single node a childRemoved event is triggered. So if we just check for a specific child to be removed, we will never be notified. This commit manually triggers the event recursively for all children but this should probably go directly into simgear. --- src/Canvas/property_based_mgr.cxx | 4 +++- src/Canvas/property_helper.cxx | 11 +++++++++++ src/Canvas/property_helper.hxx | 6 ++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Canvas/property_based_mgr.cxx b/src/Canvas/property_based_mgr.cxx index d02e7ed6f..148c96e32 100644 --- a/src/Canvas/property_based_mgr.cxx +++ b/src/Canvas/property_based_mgr.cxx @@ -83,7 +83,9 @@ void PropertyBasedMgr::childAdded( SGPropertyNode * parent, void PropertyBasedMgr::childRemoved( SGPropertyNode * parent, SGPropertyNode * child ) { - if( parent != _props || child->getNameString() != _name_elements ) + if( parent != _props ) + return canvas::triggerRemoveRecursive(child); + else if( child->getNameString() != _name_elements ) return; size_t index = child->getIndex(); diff --git a/src/Canvas/property_helper.cxx b/src/Canvas/property_helper.cxx index ce5add9dd..3579ad6e1 100644 --- a/src/Canvas/property_helper.cxx +++ b/src/Canvas/property_helper.cxx @@ -144,4 +144,15 @@ namespace canvas for( int i = 0; i < node->nChildren(); ++i ) triggerChangeRecursive( node->getChild(i) ); } + + //---------------------------------------------------------------------------- + void triggerRemoveRecursive(SGPropertyNode* node) + { + for( int i = 0; i < node->nChildren(); ++i ) + { + SGPropertyNode* child = node->getChild(i); + node->fireChildRemoved( child ); + triggerRemoveRecursive( child ); + } + } } diff --git a/src/Canvas/property_helper.hxx b/src/Canvas/property_helper.hxx index a92c04666..92e556afc 100644 --- a/src/Canvas/property_helper.hxx +++ b/src/Canvas/property_helper.hxx @@ -98,6 +98,12 @@ namespace canvas */ void triggerChangeRecursive(SGPropertyNode* node); + /** + * Trigger a childRemoved event for every child of node (Unlimited depth) and + * node itself. + */ + void triggerRemoveRecursive(SGPropertyNode* node); + } // namespace canvas #endif /* PROPERTY_HELPER_HXX_ */