diff --git a/simgear/scene/model/modellib.hxx b/simgear/scene/model/modellib.hxx index 10a2fc1e..287c2e80 100644 --- a/simgear/scene/model/modellib.hxx +++ b/simgear/scene/model/modellib.hxx @@ -93,6 +93,7 @@ public: virtual ~SGModelData() {} virtual void modelLoaded(const std::string& path, SGPropertyNode *prop, osg::Node* branch) = 0; + virtual SGModelData* clone() const = 0; }; } diff --git a/simgear/scene/tgdb/ReaderWriterSTG.cxx b/simgear/scene/tgdb/ReaderWriterSTG.cxx index fe4f302a..6f520b9b 100644 --- a/simgear/scene/tgdb/ReaderWriterSTG.cxx +++ b/simgear/scene/tgdb/ReaderWriterSTG.cxx @@ -185,6 +185,14 @@ struct ReaderWriterSTG::_ModelBin { std::string fg_root = options->getPluginStringData("SimGear::FG_ROOT"); sharedOptions->getDatabasePathList().push_back(fg_root); + // TODO how should we handle this for OBJECT_SHARED? + sharedOptions->setModelData + ( + sharedOptions->getModelData() + ? sharedOptions->getModelData()->clone() + : 0 + ); + return sharedOptions.release(); } SGReaderWriterOptions* staticOptions(const std::string& filePath, const osgDB::Options* options) @@ -196,6 +204,15 @@ struct ReaderWriterSTG::_ModelBin { staticOptions->getDatabasePathList().push_back(filePath); staticOptions->setObjectCacheHint(osgDB::Options::CACHE_NONE); + // Every model needs its own SGModelData to ensure load/unload is + // working properly + staticOptions->setModelData + ( + staticOptions->getModelData() + ? staticOptions->getModelData()->clone() + : 0 + ); + return staticOptions.release(); }