Keep a reference to the original scene template for as long as the instance is used

This commit is contained in:
scrawl 2016-02-07 18:56:21 +01:00
parent 778bce3ae9
commit 41233fc8e5
2 changed files with 4 additions and 2 deletions

View file

@ -23,12 +23,10 @@ namespace Resource
ObjectCache::ObjectCache():
osg::Referenced(true)
{
// OSG_NOTICE<<"Constructed ObjectCache"<<std::endl;
}
ObjectCache::~ObjectCache()
{
// OSG_NOTICE<<"Destructed ObjectCache"<<std::endl;
}
void ObjectCache::addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp)

View file

@ -373,6 +373,10 @@ namespace Resource
{
osg::ref_ptr<const osg::Node> scene = getTemplate(name);
osg::ref_ptr<osg::Node> cloned = osg::clone(scene.get(), SceneUtil::CopyOp());
// add a ref to the original template, to hint to the cache that it's still being used and should be kept in cache
cloned->getOrCreateUserDataContainer()->addUserObject(const_cast<osg::Node*>(scene.get()));
return cloned;
}