From cb9919ef7459f0ecf8660d858ef1188069a1bc89 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 13 Nov 2014 21:02:58 +0000 Subject: [PATCH] Drop ground-nets cache on scenery path change. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Unfortunately we can’t drop loaded ones, since the in-memory structures don’t have ref-counting, and we don’t know what AI plans may be referencing them. --- src/Main/fg_commands.cxx | 7 +++++++ src/Navaids/NavDataCache.cxx | 22 +++++++++++++++------- src/Navaids/NavDataCache.hxx | 8 +++++++- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 175a9dd86..2d2767a55 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -39,6 +39,7 @@ #include #include #include +#include #include "fg_init.hxx" #include "fg_io.hxx" @@ -1451,6 +1452,12 @@ do_set_scenery_paths(const SGPropertyNode* arg) root.append("Scenery"); globals->append_fg_scenery(root.str()); } + + // might need to drop ground-nets from the DB. Also need to drop + // them from memory, but this is tricky since FGAirportDynamics holds + // an instance directly, and AI code may have pointers to ground-net + // nodes. For now we'll leave-in memory versions untouched. + flightgear::NavDataCache::instance()->dropGroundnetsIfRequired(); return true; } diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 4c5a030ba..f6756613b 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -1161,17 +1161,25 @@ bool NavDataCache::isRebuildRequired() SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: main cache rebuild required"); return true; } - - string sceneryPaths = simgear::strutils::join(globals->get_fg_scenery(), ";"); - if (readStringProperty("scenery_paths") != sceneryPaths) { - SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: scenery paths changed,dropping ground net"); - dropAllGroundnets(); - writeStringProperty("scenery_paths", sceneryPaths); - } + + dropGroundnetsIfRequired(); SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: no main cache rebuild required"); return false; } + +bool NavDataCache::dropGroundnetsIfRequired() +{ + string sceneryPaths = simgear::strutils::join(globals->get_fg_scenery(), ";"); + if (readStringProperty("scenery_paths") != sceneryPaths) { + SG_LOG(SG_NAVCACHE, SG_INFO, "NavCache: scenery paths changed, dropping ground nets"); + dropAllGroundnets(); + writeStringProperty("scenery_paths", sceneryPaths); + return true; + } + + return false; +} bool NavDataCache::rebuild() { diff --git a/src/Navaids/NavDataCache.hxx b/src/Navaids/NavDataCache.hxx index 3a6ef313c..e5d9e7c06 100644 --- a/src/Navaids/NavDataCache.hxx +++ b/src/Navaids/NavDataCache.hxx @@ -64,7 +64,13 @@ public: ** global input files is changed. */ bool isRebuildRequired(); - + + /** + * check if cached scenery paths have changed, and if so, drop scenery- + * dependant data such as ground-nets. + */ + bool dropGroundnetsIfRequired(); + /** * run the cache rebuild - returns true if rebuild is complete, * otherwise keep going. -- 2.39.5