From f8fc4f66a8e1829141ed8ded648925f41f60c736 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 22 Jan 2010 20:47:39 +0000 Subject: [PATCH] Added RequestQueue destructor and DatabaseRequest::invalidate() and valid() methods to allow the destruction of RequestQueue to remove any pointers held in DatabaseRequest attached to the scene graph, and to prevent their subsequent use in cases where the scene graph is attached to a new DatabasePager. --- include/osgDB/DatabasePager | 16 +++++++++++++--- src/osgDB/DatabasePager.cpp | 30 +++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index d6eb751ad..099de9f0a 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -350,6 +350,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl { DatabaseRequest(): osg::Referenced(true), + _valid(false), _frameNumberFirstRequest(0), _timestampFirstRequest(0.0), _priorityFirstRequest(0.f), @@ -359,7 +360,12 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl _numOfRequests(0), _requestQueue(0) {} - + + void invalidate(); + + bool valid() const { return _valid; } + + bool _valid; std::string _fileName; int _frameNumberFirstRequest; double _timestampFirstRequest; @@ -371,7 +377,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl osg::observer_ptr _groupForAddingLoadedSubgraph; osg::ref_ptr _loadedModel; DataToCompileMap _dataToCompileMap; - osg::ref_ptr _loadOptions; + osg::ref_ptr _loadOptions; RequestQueue* _requestQueue; bool isRequestCurrent (int frameNumber) const @@ -382,12 +388,16 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl struct RequestQueue : public osg::Referenced { + public: typedef std::vector< osg::ref_ptr > RequestList; void sort(); - + RequestList _requestList; OpenThreads::Mutex _requestMutex; + + protected: + virtual ~RequestQueue(); }; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 28da47b74..89362a785 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -279,8 +279,30 @@ struct DatabasePager::SortFileRequestFunctor ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // -// ReadQueue +// RequestQueue // +void DatabasePager::DatabaseRequest::invalidate() +{ + osg::notify(osg::INFO)<<" DatabasePager::DatabaseRequest::invalidate()."<invalidate(); + } +} + void DatabasePager::RequestQueue::sort() { std::sort(_requestList.begin(),_requestList.end(),SortFileRequestFunctor()); @@ -1295,6 +1317,12 @@ void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* grou if (databaseRequestRef.valid()) { DatabaseRequest* databaseRequest = dynamic_cast(databaseRequestRef.get()); + if (databaseRequest && databaseRequest->valid()) + { + osg::notify(osg::NOTICE)<<"DatabaseRequest has been previously invalidated whilst still attached to scene graph."<