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.
This commit is contained in:
parent
40a6a1afd0
commit
f8fc4f66a8
@ -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<osg::Group> _groupForAddingLoadedSubgraph;
|
||||
osg::ref_ptr<osg::Node> _loadedModel;
|
||||
DataToCompileMap _dataToCompileMap;
|
||||
osg::ref_ptr<Options> _loadOptions;
|
||||
osg::ref_ptr<Options> _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<DatabaseRequest> > RequestList;
|
||||
|
||||
void sort();
|
||||
|
||||
|
||||
RequestList _requestList;
|
||||
OpenThreads::Mutex _requestMutex;
|
||||
|
||||
protected:
|
||||
virtual ~RequestQueue();
|
||||
};
|
||||
|
||||
|
||||
|
@ -279,8 +279,30 @@ struct DatabasePager::SortFileRequestFunctor
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// ReadQueue
|
||||
// RequestQueue
|
||||
//
|
||||
void DatabasePager::DatabaseRequest::invalidate()
|
||||
{
|
||||
osg::notify(osg::INFO)<<" DatabasePager::DatabaseRequest::invalidate()."<<std::endl;
|
||||
_valid = false;
|
||||
_groupForAddingLoadedSubgraph = 0;
|
||||
_loadedModel = 0;
|
||||
_dataToCompileMap.clear();
|
||||
_requestQueue = 0;
|
||||
_requestQueue = 0;
|
||||
}
|
||||
|
||||
DatabasePager::RequestQueue::~RequestQueue()
|
||||
{
|
||||
osg::notify(osg::INFO)<<"DatabasePager::RequestQueue::~RequestQueue() Destructing queue."<<std::endl;
|
||||
for(RequestList::iterator itr = _requestList.begin();
|
||||
itr != _requestList.end();
|
||||
++itr)
|
||||
{
|
||||
(*itr)->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<DatabaseRequest*>(databaseRequestRef.get());
|
||||
if (databaseRequest && databaseRequest->valid())
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"DatabaseRequest has been previously invalidated whilst still attached to scene graph."<<std::endl;
|
||||
databaseRequest = 0;
|
||||
}
|
||||
|
||||
if (databaseRequest)
|
||||
{
|
||||
osg::notify(osg::INFO)<<"DatabasePager::requestNodeFile("<<fileName<<") updating already assigned."<<std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user