]> git.mxchange.org Git - flightgear.git/commitdiff
Fix SceneryPager destruction sequence.
authorThorstenB <brehmt@gmail.com>
Sun, 15 Apr 2012 13:30:44 +0000 (15:30 +0200)
committerThorstenB <brehmt@gmail.com>
Sun, 15 Apr 2012 13:30:44 +0000 (15:30 +0200)
SceneryPager singleton must not be removed while FGScenery is still alive,
so hold a reference to it in FGScenery, saving the pager from being
deleted first.

src/AIModel/AIBase.cxx
src/Scenery/scenery.cxx
src/Scenery/scenery.hxx
src/Scenery/tilemgr.cxx
src/Scenery/tilemgr.hxx

index 44494dc54a1a852d46c482a85f816d1398617697..0945a13e6f7308a5cb9e716709402ffe041b9164 100644 (file)
@@ -175,7 +175,7 @@ FGAIBase::removeModel()
         aip.init( 0 );
         _model = 0;
         // pass it on to the pager, to be be deleted in the pager thread
-        pSceneryManager->getPagerSingleton()->queueDeleteRequest(temp);
+        pSceneryManager->getPager()->queueDeleteRequest(temp);
     }
     else
     {
index 12c3ebb69029e40fa8d99f2dfecddbddbe568b8b..908f4da22870e9bc226cd02f1364fa950637198d 100644 (file)
@@ -212,6 +212,8 @@ private:
 FGScenery::FGScenery()
 {
     SG_LOG( SG_TERRAIN, SG_INFO, "Initializing scenery subsystem" );
+    // keep reference to pager singleton, so it cannot be destroyed while FGScenery lives
+    _pager = FGScenery::getPagerSingleton();
 }
 
 FGScenery::~FGScenery() {
@@ -327,7 +329,7 @@ bool FGScenery::scenery_available(const SGGeod& position, double range_m)
     SGVec3f p = SGVec3f::fromGeod(SGGeod::fromGeodM(position, elev));
     osg::FrameStamp* framestamp
             = globals->get_renderer()->getViewer()->getFrameStamp();
-    simgear::CheckSceneryVisitor csnv(getPagerSingleton(), toOsg(p), range_m, framestamp);
+    simgear::CheckSceneryVisitor csnv(_pager, toOsg(p), range_m, framestamp);
     // currently the PagedLODs will not be loaded by the DatabasePager
     // while the splashscreen is there, so CheckSceneryVisitor force-loads
     // missing objects in the main thread
index bd976ba231ce82121a8ce1895528aa7fe8821bf6..b83b8adb9079a732141b1389146db78d455ddff6 100644 (file)
@@ -48,6 +48,7 @@ class FGScenery : public SGSubsystem {
     osg::ref_ptr<osg::Group> terrain_branch;
     osg::ref_ptr<osg::Group> models_branch;
     osg::ref_ptr<osg::Group> aircraft_branch;
+    osg::ref_ptr<flightgear::SceneryPager> _pager;
 
 public:
 
@@ -74,9 +75,9 @@ public:
                          const SGMaterial** material,
                          const osg::Node* butNotFrom = 0);
 
-    /// Compute the elevation of the scenery beow the cartesian point pos.
+    /// Compute the elevation of the scenery below the cartesian point pos.
     /// you the returned scenery altitude is not higher than the position
-    /// pos plus an ofset given with max_altoff.
+    /// pos plus an offset given with max_altoff.
     /// If the exact flag is set to true, the scenery center is moved to
     /// gain a higher accuracy of that query. The center is restored past
     /// that to the original value.
@@ -92,7 +93,7 @@ public:
     /// Compute the nearest intersection point of the line starting from 
     /// start going in direction dir with the terrain.
     /// The input and output values should be in cartesian coordinates in the
-    /// usual earth centered wgs84 coordiante system. Units are meters.
+    /// usual earth centered wgs84 coordinate system. Units are meters.
     /// On success, true is returned.
     bool get_cart_ground_intersection(const SGVec3d& start, const SGVec3d& dir,
                                       SGVec3d& nearestHit,
@@ -103,7 +104,7 @@ public:
     osg::Group *get_models_branch () const { return models_branch.get(); }
     osg::Group *get_aircraft_branch () const { return aircraft_branch.get(); }
 
-    /// Returns true if scenery is avaliable for the given lat, lon position
+    /// Returns true if scenery is available for the given lat, lon position
     /// within a range of range_m.
     /// lat and lon are expected to be in degrees.
     bool scenery_available(const SGGeod& position, double range_m);
@@ -111,6 +112,7 @@ public:
     // Static because access to the pager is needed before the rest of
     // the scenery is initialized.
     static flightgear::SceneryPager* getPagerSingleton();
+    flightgear::SceneryPager* getPager() { return _pager.get(); }
 };
 
 
index 0f566485b4c11f3a4453792783c615e18dacafb6..3471316556189dcf2caba00900698977dc2d9258 100644 (file)
@@ -60,7 +60,8 @@ FGTileMgr::FGTileMgr():
     _terra_sync(NULL),
     _visibilityMeters(fgGetNode("/environment/visibility-m", true)),
     _maxTileRangeM(fgGetNode("/sim/rendering/static-lod/bare", true)),
-    _disableNasalHooks(fgGetNode("/sim/temp/disable-scenery-nasal", true))
+    _disableNasalHooks(fgGetNode("/sim/temp/disable-scenery-nasal", true)),
+    _pager(FGScenery::getPagerSingleton())
 {
 }
 
@@ -233,7 +234,6 @@ void FGTileMgr::schedule_needed(const SGBucket& curr_bucket, double vis)
  */
 void FGTileMgr::update_queues()
 {
-    SceneryPager* pager = FGScenery::getPagerSingleton();
     osg::FrameStamp* framestamp
         = globals->get_renderer()->getViewer()->getFrameStamp();
     double current_time = framestamp->getReferenceTime();
@@ -261,12 +261,12 @@ void FGTileMgr::update_queues()
                   e->is_current_view() ))
             {
                 // schedule tile for loading with osg pager
-                pager->queueRequest(e->tileFileName,
-                                    e->getNode(),
-                                    e->get_priority(),
-                                    framestamp,
-                                    e->getDatabaseRequest(),
-                                    _options.get());
+                _pager->queueRequest(e->tileFileName,
+                                     e->getNode(),
+                                     e->get_priority(),
+                                     framestamp,
+                                     e->getDatabaseRequest(),
+                                     _options.get());
                 loading++;
             }
         } else
@@ -293,7 +293,7 @@ void FGTileMgr::update_queues()
             delete old;
             // zeros out subgraph ref_ptr, so subgraph is owned by
             // the pager and will be deleted in the pager thread.
-            pager->queueDeleteRequest(subgraph);
+            _pager->queueDeleteRequest(subgraph);
             
             if (--drop_count > 0)
                 drop_index = tile_cache.get_drop_tile();
index 241e403962491593b4f5af3e976104460faa01d0..9f9473d1a219154a56f53fa7ad9bc22f2867d999 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <simgear/structure/subsystem_mgr.hxx>
 #include <simgear/bucket/newbucket.hxx>
+#include "SceneryPager.hxx"
 #include "tileentry.hxx"
 #include "tilecache.hxx"
 
@@ -85,7 +86,9 @@ private:
 
     SGPropertyNode_ptr _visibilityMeters;
     SGPropertyNode_ptr _maxTileRangeM, _disableNasalHooks;
-    
+
+    osg::ref_ptr<flightgear::SceneryPager> _pager;
+
 public:
     FGTileMgr();