diff --git a/src/osgPlugins/txp/trPagePageManager.cpp b/src/osgPlugins/txp/trPagePageManager.cpp index d409549e6..715395044 100644 --- a/src/osgPlugins/txp/trPagePageManager.cpp +++ b/src/osgPlugins/txp/trPagePageManager.cpp @@ -148,14 +148,19 @@ bool OSGPageManager::StartThread(ThreadMode mode,ThreadID &newThread) bool OSGPageManager::EndThread() { // locationChangeEvent.release(); - pagingThread.cancel(); + + if( pagingThread.isRunning() ) + { + pagingThread.cancel(); + pagingThread.join(); + } return true; } void OSGPageManager::LoadOneTile(trpgManagedTile* tile) { - osg::Group* tileGroup; - osg::Group* parentNode ; + osg::Group* tileGroup = 0; + osg::Group* parentNode = 0; int x,y,lod; tile->GetTileLoc(x,y,lod); @@ -170,10 +175,13 @@ void OSGPageManager::LoadOneTile(trpgManagedTile* tile) // we only put tiles with NULL parent to merge list // others are referenced when added as a child osgGuard g(changeListMutex); - if(parentNode) - parentNode->addChild(tileGroup) ; - else - toMerge.push_back( tileGroup) ; +// if(parentNode) +// parentNode->addChild(tileGroup) ; +// else + if(parentNode) + toMerge.push_back(MergePair(parentNode,tileGroup)) ; + else + toMerge.push_back(MergePair(0,tileGroup)) ; //toMergeParent.push_back(parentNode ); } else @@ -265,7 +273,10 @@ bool OSGPageManager::ThreadLoop(PagingThread* t) for (unsigned int gi=0;giunref(); + } } #endif @@ -280,6 +291,9 @@ bool OSGPageManager::ThreadLoop(PagingThread* t) LoadOneTile(tile); // Now add this tile to the merge list pageManage->AckLoad(); + + //OpenThreads::Thread::Yield(); + } @@ -321,7 +335,7 @@ void OSGPageManager::UpdatePositionThread(double inLocX,double inLocY) */ bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode) { - std::vector mergeList; + std::vector mergeList; std::vector unhookList; // Make local copies of the merge and unhook lists @@ -345,19 +359,22 @@ bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode) { osg::Group *unhookMe = unhookList[ui]; + // better safe than sorry + if(!unhookMe ) continue; + // relase textre objects and display lists in subgraph. unhookMe->accept(rtadv); - // better safe than sorry - - if(!unhookMe ) continue; // Look for its parent(s) // Only expecting one, but it doesn't matter const osg::Node::ParentList &parents = unhookMe->getParents(); for (unsigned int pi=0;piremoveChild(unhookMe); + } } } @@ -372,14 +389,16 @@ bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode) // Do the merging last { - for (unsigned int mi=0;miaddChild(mergeMe); -// else - rootNode->addChild(mergeMe); + if (parent) + parent->addChild(mergeMe); + else + rootNode->addChild(mergeMe); } } diff --git a/src/osgPlugins/txp/trPagePageManager.h b/src/osgPlugins/txp/trPagePageManager.h index 8dd9abb42..50973c286 100644 --- a/src/osgPlugins/txp/trPagePageManager.h +++ b/src/osgPlugins/txp/trPagePageManager.h @@ -154,7 +154,8 @@ namespace txp // Lock for the change lists (merge, unhook, delete) ThreadMutex changeListMutex; // Merge list is filled in by the paging thread. - std::vector toMerge; + typedef std::pair< osg::ref_ptr , osg::ref_ptr > MergePair; + std::vector< MergePair > toMerge; // no need for that // std::vector toMergeParent; // Unhook list is filled in by the paging thread