]> git.mxchange.org Git - simgear.git/commitdiff
Ensure every scenery model has own SGModelData.
authorThomas Geymayer <tomgey@gmail.com>
Mon, 1 Apr 2013 11:22:28 +0000 (13:22 +0200)
committerThomas Geymayer <tomgey@gmail.com>
Mon, 1 Apr 2013 11:22:28 +0000 (13:22 +0200)
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.

simgear/scene/model/modellib.hxx
simgear/scene/tgdb/ReaderWriterSTG.cxx

index 10a2fc1ebb3e5d7482a77314033cf53e64a93fc7..287c2e807ac26102f88707561c70613d778ff452 100644 (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;
 };
 
 }
index fe4f302a7e3436d884bcb1d554403a03f39f45d4..6f520b9bcfe278427e4d8465b0958cfc53f8bc06 100644 (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();
     }