From Lauren Voerman, "In order to speed up loading large scenes (especially from network disk) I added code to our viewer to setup multiple database-pagers and request the files trough a database-request:
databasePager->setUpThreads(16, 1); We experienced problems with multiple databasepagers loading files in parallel, when two threads start to load the same file (usually a texture referenced by multiple models). The second thread to add the file to the cache (sometimes) manages to do so while the refcount from the cached object still is zero, causing the object loaded to be destroyed. Sometimes the second thread manages to ref() the object before Referenced::signalObserversAndDelete does the final recount check, causing a warning: "Warning Referenced::signalObserversAndDelete(,,) doing delete with _refCount=1" With a deleted object added to the scenegraph we get some undesired results, I think the program only crashes if the object was a Node, and just has some untextured surfaces if it was a texture, but I'm not completely sure. Attached is a modified version of the Registry.cpp, returning the object in cache and let the duplicate loaded object to be destroyed. A more efficient option would be to add some sort of blocking entry to the objectcache to stop the second thread from reading the file, and just wait until the first thread added it to the cache. If you think that's worthwile we would be happy to implement that version. A bit tricky to implement and test, that's why I submit a simple version that stops my program from crashing." git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14300 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
parent
93cf84da3e
commit
67f98edc05
@ -1250,9 +1250,21 @@ ReaderWriter::ReadResult Registry::readImplementation(const ReadFunctor& readFun
|
|||||||
ReaderWriter::ReadResult rr = read(readFunctor);
|
ReaderWriter::ReadResult rr = read(readFunctor);
|
||||||
if (rr.validObject())
|
if (rr.validObject())
|
||||||
{
|
{
|
||||||
|
// search AGAIN for entry in the object cache.
|
||||||
|
{
|
||||||
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||||
|
ObjectCache::iterator oitr = _objectCache.find(file);
|
||||||
|
if (oitr != _objectCache.end())
|
||||||
|
{
|
||||||
|
OSG_INFO << "returning cached instanced of " << file << std::endl;
|
||||||
|
if (readFunctor.isValid(oitr->second.first.get())) return ReaderWriter::ReadResult(oitr->second.first.get(), ReaderWriter::ReadResult::FILE_LOADED_FROM_CACHE);
|
||||||
|
else return ReaderWriter::ReadResult("Error file does not contain an osg::Object");
|
||||||
|
}
|
||||||
// update cache with new entry.
|
// update cache with new entry.
|
||||||
OSG_INFO<<"Adding to object cache "<<file<<std::endl;
|
OSG_INFO<<"Adding to object cache "<<file<<std::endl;
|
||||||
addEntryToObjectCache(file,rr.getObject());
|
//addEntryToObjectCache(file,rr.getObject()); //copy implementation: we already have the _objectCacheMutex lock
|
||||||
|
_objectCache[file] = ObjectTimeStampPair(rr.getObject(), 0.0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user