Commit 2f33e286 authored by Jan Möbius's avatar Jan Möbius
Browse files

Remove all children from additional node when deleting the subtree(otherwise...

Remove all children from additional node when deleting the subtree(otherwise we get dangling pointers)

git-svn-id: 383ad7c9-94d9-4d36-a494-682f7c89f535
parent b137c00a
......@@ -106,8 +106,28 @@ bool BaseObjectData::removeAdditionalNode(NodeT*& _node, QString _pluginName, QS
_node = dynamic_cast<NodeT*>(additionalNodes_[i].first);
if (_node != NULL) //valid node delete subtree
// Delete parent node from additional nodes list
additionalNodes_.erase (additionalNodes_.begin()+i);
// Remove children from list, too, since the objects will be deleted
// on delete_subtree() but (invalid) pointers reside in the additionalNodes_ list
// if not removed manually. We need to do this recursively:
std::stack<BaseNode *> children;
BaseNode *current =;
for(BaseNode::ChildIter it = current->childrenBegin(); it != current->childrenEnd(); ++it)
for(int j = additionalNodes_.size()-1; j >= 0; --j)
if(additionalNodes_[j].first == current)
// Delete nodes recursively
additionalNodes_.erase (additionalNodes_.begin()+i);
return true;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment