diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index cfb49ea5c..91f130c2c 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -1569,10 +1569,14 @@ public: virtual void apply(osg::PagedLOD& plod) { ++_numPagedLODs; + _pagedLODs.insert(&plod); traverse(plod); } - - int _numPagedLODs; + + + typedef std::set PagedLODset; + PagedLODset _pagedLODs; + int _numPagedLODs; }; void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) @@ -1684,15 +1688,16 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) for(PagedLODList::iterator itr = _inactivePagedLODList.begin(); itr!=_inactivePagedLODList.end() && countPagedLODsVisitor._numPagedLODs plod = itr->lock(); - if (plod.valid()) + if (plod.valid() && countPagedLODsVisitor._pagedLODs.count(plod.get())==0) { osg::NodeList localChildrenRemoved; plod->removeExpiredChildren(expiryTime, expiryFrame, localChildrenRemoved); if (!localChildrenRemoved.empty()) { + for(osg::NodeList::iterator critr = localChildrenRemoved.begin(); critr!=localChildrenRemoved.end(); ++critr) @@ -1702,19 +1707,23 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) std::copy(localChildrenRemoved.begin(),localChildrenRemoved.end(),std::back_inserter(childrenRemoved)); } + + // advance the iterator to the next element + ++itr; } else { + itr = _inactivePagedLODList.erase(itr); OSG_NOTICE<<"DatabasePager::removeExpiredSubgraphs() _inactivePagedLOD has been invalidated, but ignored"< plod = itr->lock(); - if (plod.valid()) + if (plod.valid() && countPagedLODsVisitor._pagedLODs.count(plod.get())==0) { osg::NodeList localChildrenRemoved; plod->removeExpiredChildren(expiryTime, expiryFrame, localChildrenRemoved); @@ -1729,9 +1738,13 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) std::copy(localChildrenRemoved.begin(),localChildrenRemoved.end(),std::back_inserter(childrenRemoved)); } + + // advance the iterator to the next element + ++itr; } else { + itr = _inactivePagedLODList.erase(itr); OSG_NOTICE<<"DatabasePager::removeExpiredSubgraphs() _activePagedLOD has been invalidated, but ignored"<