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.
This commit is contained in:
Thomas Geymayer
2013-04-01 13:22:28 +02:00
parent b6c542b0e7
commit c41caeaf64
2 changed files with 18 additions and 0 deletions

View File

@@ -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;
};
}

View File

@@ -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();
}