]> git.mxchange.org Git - flightgear.git/commitdiff
Crash-fix: mat-lib is now reference-counted.
authorJames Turner <zakalawe@mac.com>
Sun, 19 Jan 2014 16:49:32 +0000 (16:49 +0000)
committerJames Turner <zakalawe@mac.com>
Sun, 19 Jan 2014 16:49:44 +0000 (16:49 +0000)
Adapt to corresponding SG change to make SGMaterialLib be ref-counted,
and have the 'reload-materials' command notify the tile-manager of this,
so it can update the options struct it passes to new tiles.

src/Main/fg_commands.cxx
src/Main/globals.cxx
src/Main/globals.hxx
src/Scenery/tilemgr.cxx
src/Scenery/tilemgr.hxx
utils/fgelev/fgelev.cxx
utils/fgviewer/fgviewer.cxx

index 4c0f580b0d87051c9efe8a2927cc25835ea0a2d5..efbb4a97124c253c514dae1e263fc65f9540c399 100644 (file)
@@ -31,6 +31,7 @@
 #include <GUI/dialog.hxx>
 #include <Aircraft/replay.hxx>
 #include <Scenery/scenery.hxx>
+#include <Scenery/tilemgr.hxx>
 #include <Scripting/NasalSys.hxx>
 #include <Sound/sample_queue.hxx>
 #include <Airports/xmlloader.hxx>
@@ -500,26 +501,29 @@ do_tile_cache_reload (const SGPropertyNode * arg)
 /**
  * Reload the materials definition
  */
- static bool
- do_materials_reload (const SGPropertyNode * arg)
- {
-   SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
-   SGMaterialLib* new_matlib =  new SGMaterialLib;
-   SGPath mpath( globals->get_fg_root() );
-   mpath.append( fgGetString("/sim/rendering/materials-file") );
-   bool loaded = new_matlib->load(globals->get_fg_root(), 
+static bool
+do_materials_reload (const SGPropertyNode * arg)
+{
+    SG_LOG(SG_INPUT, SG_INFO, "Reloading Materials");
+    SGMaterialLib* new_matlib =  new SGMaterialLib;
+    SGPath mpath( globals->get_fg_root() );
+    mpath.append( fgGetString("/sim/rendering/materials-file") );
+    bool loaded = new_matlib->load(globals->get_fg_root(), 
                                   mpath.str(), 
                                   globals->get_props());
-   
-   if ( ! loaded ) {
+
+    if ( ! loaded ) {
        SG_LOG( SG_GENERAL, SG_ALERT,
                "Error loading materials file " << mpath.str() );
        return false;
-   }  
-   
-   globals->set_matlib(new_matlib);    
-   return true;   
- }
+    }  
+
+    globals->set_matlib(new_matlib);    
+    FGTileMgr* tileManager = static_cast<FGTileMgr*>(globals->get_subsystem("tile-manager"));
+    tileManager->materialLibChanged();
+    
+    return true;
+}
 
 
 #if 0
index d0a3d102e9ca4644590ecf0af21eeb8dd5a0f4d0..e21e5b59127c05ca913e9671e22ef9b6e7e2880d 100644 (file)
@@ -145,7 +145,6 @@ FGGlobals::FGGlobals() :
     fg_home( "" ),
     time_params( NULL ),
     ephem( NULL ),
-    matlib( NULL ),
     route_mgr( NULL ),
     ATIS_mgr( NULL ),
     controls( NULL ),
@@ -764,8 +763,6 @@ void FGGlobals::set_tile_mgr ( FGTileMgr *t )
 
 void FGGlobals::set_matlib( SGMaterialLib *m )
 {
-    if (matlib)
-        delete matlib;
     matlib = m;
 }
 
index 8f1736f146b125697138e43feb1638487bedbc12..d36090846047ad871131c59e7695dffe86598550 100644 (file)
@@ -114,7 +114,7 @@ private:
     SGEphemeris *ephem;
 
     // Material properties library
-    SGMaterialLib *matlib;
+    SGSharedPtr<SGMaterialLib> matlib;
 
     // Global autopilot "route"
     FGRouteMgr *route_mgr;
index 3df77c0e531c3d753d148ce2fd167cc4f4f8081b..ce3fd774225ae99947964859b21b32c02a144925 100644 (file)
@@ -86,7 +86,8 @@ void FGTileMgr::init() {
     SG_LOG( SG_TERRAIN, SG_INFO, "Initializing Tile Manager subsystem." );
 
     _options = new simgear::SGReaderWriterOptions;
-    _options->setMaterialLib(globals->get_matlib());
+    
+    materialLibChanged();
     _options->setPropertyNode(globals->get_props());
 
     osgDB::FilePathList &fp = _options->getDatabasePathList();
@@ -116,8 +117,7 @@ void FGTileMgr::reinit()
     fgSetBool("/sim/sceneryloaded",false);
     fgSetDouble("/sim/startup/splash-alpha", 1.0);
     
-    // Reload the materials definitions
-    _options->setMaterialLib(globals->get_matlib());
+    materialLibChanged();
 
     // remove all old scenery nodes from scenegraph and clear cache
     osg::Group* group = globals->get_scenery()->get_terrain_branch();
@@ -141,6 +141,12 @@ void FGTileMgr::reinit()
     update(0.0);
 }
 
+void FGTileMgr::materialLibChanged()
+{
+    _options->setMaterialLib(globals->get_matlib());
+    _options->getMaterialLib()->refreshActiveMaterials();
+}
+
 /* schedule a tile for loading, keep request for given amount of time.
  * Returns true if tile is already loaded. */
 bool FGTileMgr::sched_tile( const SGBucket& b, double priority, bool current_view, double duration)
index 2c676f73ee8c06c73d6f945466db826fa3ea1d42..323f7d8b3f791c8682d261edb44d3e29ace73d6a 100644 (file)
@@ -110,6 +110,10 @@ public:
 
     // Returns true if tiles around current view position have been loaded
     bool isSceneryLoaded();
+    
+    // notify the tile manahger the material library was reloaded,
+    // so it can pass this through to its options object
+    void materialLibChanged();
 };
 
 
index 90d7eb4f57d979c4f40dcd2df0eb9b59d02a7677..3ad0b5850cedb11276d2da157db1623b93af3088 100644 (file)
@@ -132,7 +132,7 @@ main(int argc, char** argv)
     simgear::ModelRegistry::instance();
 
     sgUserDataInit(props.get());
-    SGMaterialLib* ml = new SGMaterialLib;
+    SGMaterialLibPtr ml = new SGMaterialLib;
     SGPath mpath(fg_root);
     mpath.append("Materials/default/materials.xml");
     try {
index f8cbdaccc1c3ed705e92e4272e2efdf47a201a22..f5bb8e944b3c1326aaf6d6e5f852dda253c9631f 100644 (file)
@@ -179,7 +179,7 @@ main(int argc, char** argv)
     // FIXME Ok, replace this by querying the root of the property tree
     sgUserDataInit(props.get());
     SGSceneFeatures::instance()->setTextureCompression(SGSceneFeatures::DoNotUseCompression);
-    SGMaterialLib* ml = new SGMaterialLib;
+    SGMaterialLibPtr ml = new SGMaterialLib;
     SGPath mpath(fg_root);
     mpath.append("Materials/default/materials.xml");
     try {