From 0cc38108a5ebc6ff9e8e92997fc13168ea3de807 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 30 May 2008 11:43:04 +0000 Subject: [PATCH] Fixed cirular reference in DatabaseRequest --- include/osg/PagedLOD | 2 +- include/osgDB/DatabasePager | 22 ++++++------ src/osg/PagedLOD.cpp | 4 +++ src/osgDB/DatabasePager.cpp | 72 +++++++++++++++++++++---------------- 4 files changed, 58 insertions(+), 42 deletions(-) diff --git a/include/osg/PagedLOD b/include/osg/PagedLOD index 310d97296..c4d95e7cc 100644 --- a/include/osg/PagedLOD +++ b/include/osg/PagedLOD @@ -121,7 +121,7 @@ class OSG_EXPORT PagedLOD : public LOD protected : - virtual ~PagedLOD() {} + virtual ~PagedLOD(); void expandPerRangeDataTo(unsigned int pos); diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index fa23887af..80dec6018 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -324,17 +324,17 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl _numOfRequests(0) {} - std::string _fileName; - int _frameNumberFirstRequest; - double _timestampFirstRequest; - float _priorityFirstRequest; - int _frameNumberLastRequest; - double _timestampLastRequest; - float _priorityLastRequest; - unsigned int _numOfRequests; - osg::ref_ptr _groupForAddingLoadedSubgraph; - osg::ref_ptr _loadedModel; - DataToCompileMap _dataToCompileMap; + std::string _fileName; + int _frameNumberFirstRequest; + double _timestampFirstRequest; + float _priorityFirstRequest; + int _frameNumberLastRequest; + double _timestampLastRequest; + float _priorityLastRequest; + unsigned int _numOfRequests; + osg::observer_ptr _groupForAddingLoadedSubgraph; + osg::ref_ptr _loadedModel; + DataToCompileMap _dataToCompileMap; osg::ref_ptr _loadOptions; bool isRequestCurrent (int frameNumber) const diff --git a/src/osg/PagedLOD.cpp b/src/osg/PagedLOD.cpp index 92fcd0227..04906216c 100644 --- a/src/osg/PagedLOD.cpp +++ b/src/osg/PagedLOD.cpp @@ -59,6 +59,10 @@ PagedLOD::PagedLOD(const PagedLOD& plod,const CopyOp& copyop): { } +PagedLOD::~PagedLOD() +{ +} + void PagedLOD::setDatabasePath(const std::string& path) { _databasePath = path; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 7779fa51e..3add11b24 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -397,7 +397,7 @@ void DatabasePager::DatabaseThread::run() // // delete any children if required. // - if (_pager->_deleteRemovedSubgraphsInDatabaseThread) + if (_pager->_deleteRemovedSubgraphsInDatabaseThread && !(read_queue->_childrenToDeleteList.empty())) { ObjectList deleteList; @@ -557,12 +557,22 @@ void DatabasePager::DatabaseThread::run() osg::notify(osg::INFO)<<_name<<": Warning DatabaseRquest no longer required."<_loadedModel = 0; } + + osg::ref_ptr groupForAddingLoadedSubgraph = databaseRequest->_groupForAddingLoadedSubgraph.get(); + + if (!groupForAddingLoadedSubgraph) + { + osg::notify(osg::INFO)<<_name<<": Warning parent of loaded subgraph, deleted."<_loadedModel = 0; + } //osg::notify(osg::NOTICE)<<" node read in "<delta_m(before,osg::Timer::instance()->tick())<<" ms"<_doPreCompile && databaseRequest->_loadedModel.valid() && !_pager->_activeGraphicsContexts.empty()) + if (_pager->_doPreCompile && + databaseRequest->_loadedModel.valid() && + !_pager->_activeGraphicsContexts.empty()) { // force a compute of the loaded model's bounding volume, so that when the subgraph // merged with the main scene graph and large computeBound() isn't incurred. @@ -582,7 +592,7 @@ void DatabasePager::DatabaseThread::run() // push the soon to be parent on the nodepath of the NodeVisitor so that // during traversal one can test for where it'll be in the overall scene graph - osg::NodePathList nodePathList = databaseRequest->_groupForAddingLoadedSubgraph->getParentalNodePaths(); + osg::NodePathList nodePathList = groupForAddingLoadedSubgraph->getParentalNodePaths(); if (!nodePathList.empty()) { osg::NodePath& nodePath = nodePathList.front(); @@ -594,7 +604,7 @@ void DatabasePager::DatabaseThread::run() } } - frov.pushOntoNodePath(databaseRequest->_groupForAddingLoadedSubgraph.get()); + frov.pushOntoNodePath(groupForAddingLoadedSubgraph.get()); databaseRequest->_loadedModel->accept(frov); @@ -1182,35 +1192,37 @@ void DatabasePager::addLoadedDataToSceneGraph(double timeStamp) registerPagedLODs(databaseRequest->_loadedModel.get()); - osg::Group* group = databaseRequest->_groupForAddingLoadedSubgraph.get(); - - osg::PagedLOD* plod = dynamic_cast(group); - if (plod) + osg::ref_ptr group = databaseRequest->_groupForAddingLoadedSubgraph.get(); + if (group.valid()) { - plod->setTimeStamp(plod->getNumChildren(),timeStamp); - plod->getDatabaseRequest(plod->getNumChildren()) = 0; - } - else - { - osg::ProxyNode* proxyNode = dynamic_cast(group); - if (proxyNode) + osg::PagedLOD* plod = dynamic_cast(group.get()); + if (plod) { - proxyNode->getDatabaseRequest(proxyNode->getNumChildren()) = 0; - } + plod->setTimeStamp(plod->getNumChildren(),timeStamp); + plod->getDatabaseRequest(plod->getNumChildren()) = 0; + } + else + { + osg::ProxyNode* proxyNode = dynamic_cast(group.get()); + if (proxyNode) + { + proxyNode->getDatabaseRequest(proxyNode->getNumChildren()) = 0; + } + } + + group->addChild(databaseRequest->_loadedModel.get()); + + osg::notify(osg::INFO)<<"merged subgraph"<_fileName<<" after "<_numOfRequests<<" requests and time="<<(timeStamp-databaseRequest->_timestampFirstRequest)*1000.0<_timestampFirstRequest; + + if (timeToMerge<_minimumTimeToMergeTile) _minimumTimeToMergeTile = timeToMerge; + if (timeToMerge>_maximumTimeToMergeTile) _maximumTimeToMergeTile = timeToMerge; + + _totalTimeToMergeTiles += timeToMerge; + ++_numTilesMerges; } - - group->addChild(databaseRequest->_loadedModel.get()); - - osg::notify(osg::INFO)<<"merged subgraph"<_fileName<<" after "<_numOfRequests<<" requests and time="<<(timeStamp-databaseRequest->_timestampFirstRequest)*1000.0<_timestampFirstRequest; - - if (timeToMerge<_minimumTimeToMergeTile) _minimumTimeToMergeTile = timeToMerge; - if (timeToMerge>_maximumTimeToMergeTile) _maximumTimeToMergeTile = timeToMerge; - - _totalTimeToMergeTiles += timeToMerge; - ++_numTilesMerges; - + // reset the loadedModel pointer databaseRequest->_loadedModel = 0;