From: Thomas Geymayer Date: Mon, 1 Apr 2013 11:22:28 +0000 (+0200) Subject: Ensure every scenery model has own SGModelData. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c41caeaf647cad33ae0f7551ea5978f6d2afcd83;p=simgear.git Ensure every scenery model has own SGModelData. This makes Nasal unload hooks of scenery objects working again. Previously the same SGModelData instance was used for all objects which never got destroyed and therefore was not able to call any unload callback. --- 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(); }