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.
This commit is contained in:
parent
ffbb0a0e5d
commit
09ac319e87
3 changed files with 20 additions and 1 deletions
|
@ -83,7 +83,9 @@ void PropertyBasedMgr::childAdded( SGPropertyNode * parent,
|
||||||
void PropertyBasedMgr::childRemoved( SGPropertyNode * parent,
|
void PropertyBasedMgr::childRemoved( SGPropertyNode * parent,
|
||||||
SGPropertyNode * child )
|
SGPropertyNode * child )
|
||||||
{
|
{
|
||||||
if( parent != _props || child->getNameString() != _name_elements )
|
if( parent != _props )
|
||||||
|
return canvas::triggerRemoveRecursive(child);
|
||||||
|
else if( child->getNameString() != _name_elements )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t index = child->getIndex();
|
size_t index = child->getIndex();
|
||||||
|
|
|
@ -144,4 +144,15 @@ namespace canvas
|
||||||
for( int i = 0; i < node->nChildren(); ++i )
|
for( int i = 0; i < node->nChildren(); ++i )
|
||||||
triggerChangeRecursive( node->getChild(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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,12 @@ namespace canvas
|
||||||
*/
|
*/
|
||||||
void triggerChangeRecursive(SGPropertyNode* node);
|
void triggerChangeRecursive(SGPropertyNode* node);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trigger a childRemoved event for every child of node (Unlimited depth) and
|
||||||
|
* node itself.
|
||||||
|
*/
|
||||||
|
void triggerRemoveRecursive(SGPropertyNode* node);
|
||||||
|
|
||||||
} // namespace canvas
|
} // namespace canvas
|
||||||
|
|
||||||
#endif /* PROPERTY_HELPER_HXX_ */
|
#endif /* PROPERTY_HELPER_HXX_ */
|
||||||
|
|
Loading…
Reference in a new issue