2.8 branch: Merge revision 10520 from trunk to fix memory leaks.

This commit is contained in:
Paul MARTZ
2010-03-17 20:47:50 +00:00
parent 4e90ccb13a
commit 7ab4faeae1
7 changed files with 75 additions and 68 deletions

View File

@@ -886,14 +886,14 @@ DatabasePager::DatabasePager()
if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0)
{
_expiryDelay = osg::asciiToDouble(ptr);
osg::notify(osg::NOTICE)<<"Expiry delay = "<<_expiryDelay<<std::endl;
osg::notify(osg::NOTICE)<<"DatabasePager: Expiry delay = "<<_expiryDelay<<std::endl;
}
_expiryFrames = 1; // Last frame will not be expired
if( (ptr = getenv("OSG_EXPIRY_FRAMES")) != 0)
{
_expiryFrames = atoi(ptr);
osg::notify(osg::NOTICE)<<"Expiry frames = "<<_expiryFrames<<std::endl;
osg::notify(osg::NOTICE)<<"DatabasePager: Expiry frames = "<<_expiryFrames<<std::endl;
}
if( (ptr = getenv("OSG_RELEASE_DELAY")) != 0)
@@ -907,7 +907,7 @@ DatabasePager::DatabasePager()
setReleaseDelay(osg::asciiToDouble(ptr));
}
osg::notify(osg::NOTICE)<<"Release delay = "<<_releaseDelay<<std::endl;
osg::notify(osg::NOTICE)<<"DatabasePager: Release delay = "<<_releaseDelay<<std::endl;
}
else
{
@@ -1748,14 +1748,6 @@ void DatabasePager::capped_removeExpiredSubgraphs(const osg::FrameStamp& frameSt
" A="<<time_a<<" avg="<<s_total_time_stage_a/s_total_iter_stage_a<<" max = "<<s_total_max_stage_a<<
" B="<<time_b<<" avg="<<s_total_time_stage_b/s_total_iter_stage_b<<" max = "<<s_total_max_stage_b<<
" C="<<time_c<<" avg="<<s_total_time_stage_c/s_total_iter_stage_c<<" max = "<<s_total_max_stage_c<<std::endl;
if (osgDB::Registry::instance()->getSharedStateManager())
osgDB::Registry::instance()->getSharedStateManager()->prune();
// update the Registry object cache.
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp.getReferenceTime());
osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime);
}
void DatabasePager::expiry_removeExpiredSubgraphs(const osg::FrameStamp& frameStamp)
@@ -1850,16 +1842,6 @@ void DatabasePager::expiry_removeExpiredSubgraphs(const osg::FrameStamp& frameSt
osg::notify(osg::INFO)<<"_activePagedLODList.size()="<<_activePagedLODList.size()<<" overall = "<<time<<
" avg="<<s_total_time/s_total_iter<<" max = "<<s_total_max<<std::endl;
if (osgDB::Registry::instance()->getSharedStateManager())
osgDB::Registry::instance()->getSharedStateManager()->prune();
// update the Registry object cache.
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(frameStamp.getReferenceTime());
osgDB::Registry::instance()->removeExpiredObjectsInCache(expiryTime);
}
class DatabasePager::FindPagedLODsVisitor : public osg::NodeVisitor

View File

@@ -183,6 +183,15 @@ Registry::Registry()
else _buildKdTreesHint = ReaderWriter::Options::BUILD_KDTREES;
}
const char* ptr=0;
_expiryDelay = 10.0;
if( (ptr = getenv("OSG_EXPIRY_DELAY")) != 0)
{
_expiryDelay = osg::asciiToDouble(ptr);
osg::notify(osg::INFO)<<"Registry : Expiry delay = "<<_expiryDelay<<std::endl;
}
const char* fileCachePath = getenv("OSG_FILE_CACHE");
if (fileCachePath)
{
@@ -1981,7 +1990,7 @@ osg::Object* Registry::getFromObjectCache(const std::string& fileName)
else return 0;
}
void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(double currentTime)
void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(const osg::FrameStamp& frameStamp)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
@@ -1994,13 +2003,15 @@ void Registry::updateTimeStampOfObjectsInCacheWithExternalReferences(double curr
if (itr->second.first->referenceCount()>1)
{
// so update it time stamp.
itr->second.second = currentTime;
itr->second.second = frameStamp.getReferenceTime();
}
}
}
void Registry::removeExpiredObjectsInCache(double expiryTime)
void Registry::removeExpiredObjectsInCache(const osg::FrameStamp& frameStamp)
{
double expiryTime = frameStamp.getReferenceTime() - _expiryDelay;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
typedef std::vector<std::string> ObjectsToRemove;

View File

@@ -979,27 +979,18 @@ void CompositeViewer::updateTraversal()
++sitr)
{
Scene* scene = *sitr;
if (scene->getSceneData())
{
_updateVisitor->setImageRequestHandler(scene->getImagePager());
scene->getSceneData()->accept(*_updateVisitor);
}
if (scene->getDatabasePager())
{
// synchronize changes required by the DatabasePager thread to the scene graph
scene->getDatabasePager()->updateSceneGraph(*_frameStamp);
}
if (scene->getImagePager())
{
// synchronize changes required by the DatabasePager thread to the scene graph
scene->getImagePager()->updateSceneGraph(*_frameStamp);
}
scene->updateSceneGraph(*_updateVisitor);
}
// if we have a shared state manager prune any unused entries
if (osgDB::Registry::instance()->getSharedStateManager())
osgDB::Registry::instance()->getSharedStateManager()->prune();
// update the Registry object cache.
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(*getFrameStamp());
osgDB::Registry::instance()->removeExpiredObjectsInCache(*getFrameStamp());
if (_updateOperations.valid())
{
_updateOperations->runOperations(this);

View File

@@ -77,6 +77,31 @@ void Scene::setImagePager(osgDB::ImagePager* ip)
_imagePager = ip;
}
void Scene::updateSceneGraph(osg::NodeVisitor& updateVisitor)
{
if (!_sceneData) return;
if (getSceneData())
{
updateVisitor.setImageRequestHandler(getImagePager());
getSceneData()->accept(updateVisitor);
}
if (getDatabasePager())
{
// synchronize changes required by the DatabasePager thread to the scene graph
getDatabasePager()->updateSceneGraph((*updateVisitor.getFrameStamp()));
}
if (getImagePager())
{
// synchronize changes required by the DatabasePager thread to the scene graph
getImagePager()->updateSceneGraph(*(updateVisitor.getFrameStamp()));
}
}
Scene* Scene::getScene(osg::Node* node)
{

View File

@@ -876,23 +876,16 @@ void Viewer::updateTraversal()
_updateVisitor->setFrameStamp(getFrameStamp());
_updateVisitor->setTraversalNumber(getFrameStamp()->getFrameNumber());
if (getSceneData())
{
_updateVisitor->setImageRequestHandler(_scene->getImagePager());
getSceneData()->accept(*_updateVisitor);
}
if (_scene->getDatabasePager())
{
// synchronize changes required by the DatabasePager thread to the scene graph
_scene->getDatabasePager()->updateSceneGraph(*_frameStamp);
}
_scene->updateSceneGraph(*_updateVisitor);
// if we have a shared state manager prune any unused entries
if (osgDB::Registry::instance()->getSharedStateManager())
osgDB::Registry::instance()->getSharedStateManager()->prune();
// update the Registry object cache.
osgDB::Registry::instance()->updateTimeStampOfObjectsInCacheWithExternalReferences(*getFrameStamp());
osgDB::Registry::instance()->removeExpiredObjectsInCache(*getFrameStamp());
if (_scene->getImagePager())
{
// synchronize changes required by the DatabasePager thread to the scene graph
_scene->getImagePager()->updateSceneGraph(*_frameStamp);
}
if (_updateOperations.valid())
{