From 487546c848ad5559760b4de4aa36f19b9b8627a7 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 13 Mar 2014 18:18:23 +0000 Subject: [PATCH] Fix some leaks on reset - tilecache 'clear_cache' is poorly named, ensure the destructor really deletes all outstanding entries. --- src/Main/fg_init.cxx | 2 ++ src/Scenery/SceneryPager.cxx | 6 ++++++ src/Scenery/SceneryPager.hxx | 2 ++ src/Scenery/tilecache.cxx | 10 ++++++++-- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 2b293ce7f..06404440b 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -100,6 +100,7 @@ #include #include #include +#include #include #include #include @@ -982,6 +983,7 @@ void fgStartNewReset() // access the scenery object globals->set_tile_mgr(NULL); globals->set_scenery(NULL); + FGScenery::getPagerSingleton()->clearRequests(); flightgear::CameraGroup::setDefault(NULL); // don't cancel the pager until after shutdown, since AIModels (and diff --git a/src/Scenery/SceneryPager.cxx b/src/Scenery/SceneryPager.cxx index 9e128787e..892b7bc1a 100644 --- a/src/Scenery/SceneryPager.cxx +++ b/src/Scenery/SceneryPager.cxx @@ -42,6 +42,12 @@ SceneryPager::~SceneryPager() { } +void SceneryPager::clearRequests() +{ + _pagerRequests.clear(); + _deleteRequests.clear(); +} + void SceneryPager::queueRequest(const std::string& fileName, Group* group, float priority, FrameStamp* frameStamp, ref_ptr& databaseRequest, diff --git a/src/Scenery/SceneryPager.hxx b/src/Scenery/SceneryPager.hxx index d8f519a1b..b225ecfe2 100644 --- a/src/Scenery/SceneryPager.hxx +++ b/src/Scenery/SceneryPager.hxx @@ -47,6 +47,8 @@ public: // lock on the delete list. void queueDeleteRequest(osg::ref_ptr& objptr); virtual void signalEndFrame(); + + void clearRequests(); protected: // Queue up file requests until the end of the frame struct PagerRequest diff --git a/src/Scenery/tilecache.cxx b/src/Scenery/tilecache.cxx index d82d2e304..d25c38780 100644 --- a/src/Scenery/tilecache.cxx +++ b/src/Scenery/tilecache.cxx @@ -38,8 +38,14 @@ TileCache::TileCache( void ) : } -TileCache::~TileCache( void ) { - clear_cache(); +TileCache::~TileCache( void ) +{ + tile_map_iterator it = tile_cache.begin(); + for (; it != tile_cache.end(); ++it) { + TileEntry* tile = it->second; + tile->removeFromSceneGraph(); + delete tile; + } }