diff --git a/src/osgUtil/StateGraph.cpp b/src/osgUtil/StateGraph.cpp index ccad89e57..4f378f3f2 100644 --- a/src/osgUtil/StateGraph.cpp +++ b/src/osgUtil/StateGraph.cpp @@ -49,26 +49,17 @@ void StateGraph::clean() /** recursively prune the StateGraph of empty children.*/ void StateGraph::prune() { - std::vector toEraseList; - // call prune on all children. - for(ChildList::iterator citr=_children.begin(); - citr!=_children.end(); - ++citr) + ChildList::iterator citr=_children.begin(); + while(citr!=_children.end()) { citr->second->prune(); if (citr->second->empty()) { - toEraseList.push_back(citr->first); + ChildList::iterator ditr= citr++; + _children.erase(ditr); } + else ++citr; } - - for(std::vector::iterator eitr=toEraseList.begin(); - eitr!=toEraseList.end(); - ++eitr) - { - _children.erase(*eitr); - } - }