From 054d5606fb32e0e7a8c4ee36cb9fd005aa738629 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 1 Jun 2010 11:28:04 +0000 Subject: [PATCH] From Tim Moore, "This is a patch that allows a ref_ptr to be constructed using an observer_ptr argument, which is locked. This is shorthand for declaring the ref_ptr and then passing it to observer_ptr::lock(). " --- include/osg/ref_ptr | 4 +++- src/osgDB/DatabasePager.cpp | 16 ++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/include/osg/ref_ptr b/include/osg/ref_ptr index 86bb83fac..948d2f0bb 100644 --- a/include/osg/ref_ptr +++ b/include/osg/ref_ptr @@ -18,6 +18,8 @@ namespace osg { +template class observer_ptr; + /** Smart pointer for handling referenced counted objects.*/ template class ref_ptr @@ -29,7 +31,7 @@ class ref_ptr ref_ptr(T* ptr) : _ptr(ptr) { if (_ptr) _ptr->ref(); } ref_ptr(const ref_ptr& rp) : _ptr(rp._ptr) { if (_ptr) _ptr->ref(); } template ref_ptr(const ref_ptr& rp) : _ptr(rp._ptr) { if (_ptr) _ptr->ref(); } - + ref_ptr(observer_ptr& optr) : _ptr(0) { optr.lock(*this); } ~ref_ptr() { if (_ptr) _ptr->unref(); _ptr = 0; } ref_ptr& operator = (const ref_ptr& rp) diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 31d77d6ab..36fdfba26 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -1612,8 +1612,8 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) itr != _activePagedLODList.end(); ) { - osg::ref_ptr plod; - if (itr->lock(plod)) + osg::ref_ptr plod(*itr); + if (plod.valid()) { int delta = frameStamp.getFrameNumber() - plod->getFrameNumberOfLastTraversal(); if (delta>1) @@ -1643,8 +1643,8 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) itr != _inactivePagedLODList.end(); ) { - osg::ref_ptr plod; - if (itr->lock(plod)) + osg::ref_ptr plod(*itr); + if (plod.valid()) { int delta = frameStamp.getFrameNumber() - plod->getFrameNumberOfLastTraversal(); if (delta>1) @@ -1702,8 +1702,8 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) itr!=_inactivePagedLODList.end() && countPagedLODsVisitor._numPagedLODs plod; - if (itr->lock(plod) && countPagedLODsVisitor._pagedLODs.count(plod.get())==0) + osg::ref_ptr plod(*itr); + if (plod.valid() && countPagedLODsVisitor._pagedLODs.count(plod.get())==0) { countPagedLODsVisitor.removeExpiredChildrenAndCountPagedLODs(plod.get(), expiryTime, expiryFrame, childrenRemoved); @@ -1721,8 +1721,8 @@ void DatabasePager::removeExpiredSubgraphs(const osg::FrameStamp& frameStamp) itr!=_activePagedLODList.end() && countPagedLODsVisitor._numPagedLODs plod; - if (itr->lock(plod) && countPagedLODsVisitor._pagedLODs.count(plod.get())==0) + osg::ref_ptr plod(*itr); + if (plod.valid() && countPagedLODsVisitor._pagedLODs.count(plod.get())==0) { countPagedLODsVisitor.removeExpiredChildrenAndCountPagedLODs(plod.get(), expiryTime, expiryFrame, childrenRemoved);