From a5b32f8eb210a50af5d4cd07ab3db2cdc5f21a7e Mon Sep 17 00:00:00 2001 From: Richard Harrison Date: Thu, 24 Jan 2019 16:10:58 +0100 Subject: [PATCH] Fix for deleting referenced object from model registry This should have been in the previous commit - However I managed to mess up the merging of this module due to other changes related to the DDS texture cache. --- simgear/scene/model/ModelRegistry.cxx | 22 ++++++++++++---------- simgear/scene/model/ModelRegistry.hxx | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/simgear/scene/model/ModelRegistry.cxx b/simgear/scene/model/ModelRegistry.cxx index f788162a..bcb5ec9c 100644 --- a/simgear/scene/model/ModelRegistry.cxx +++ b/simgear/scene/model/ModelRegistry.cxx @@ -280,19 +280,21 @@ ModelRegistry::readImage(const string& fileName, } -osg::Node* DefaultCachePolicy::find(const string& fileName, - const Options* opt) +osg::ref_ptr DefaultCachePolicy::find(const string& fileName, const Options* opt) { Registry* registry = Registry::instance(); - osg::Node* cached - = dynamic_cast(registry->getFromObjectCache(fileName)); - if (cached) - SG_LOG(SG_IO, SG_BULK, "Got cached model \"" - << fileName << "\""); +#if OSG_VERSION_LESS_THAN(3,4,0) + osg::ref_ptr cachedObject = registry->getFromObjectCache(fileName); +#else + osg::ref_ptr cachedObject = registry->getRefFromObjectCache(fileName); +#endif + + ref_ptr cachedNode = dynamic_cast(cachedObject.get()); + if (cachedNode.valid()) + SG_LOG(SG_IO, SG_BULK, "Got cached model \"" << fileName << "\""); else - SG_LOG(SG_IO, SG_BULK, "Reading model \"" - << fileName << "\""); - return cached; + SG_LOG(SG_IO, SG_BULK, "Reading model \"" << fileName << "\""); + return cachedNode; } void DefaultCachePolicy::addToCache(const string& fileName, diff --git a/simgear/scene/model/ModelRegistry.hxx b/simgear/scene/model/ModelRegistry.hxx index 8c8e7467..197bb197 100644 --- a/simgear/scene/model/ModelRegistry.hxx +++ b/simgear/scene/model/ModelRegistry.hxx @@ -132,7 +132,7 @@ struct DefaultProcessPolicy { struct DefaultCachePolicy { DefaultCachePolicy(const std::string& extension) {} - osg::Node* find(const std::string& fileName, + osg::ref_ptr find(const std::string& fileName, const osgDB::Options* opt); void addToCache(const std::string& filename, osg::Node* node); };