diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index b72976677..7d7a0bfd3 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -1269,7 +1269,10 @@ void fgStartNewReset() // don't delete here, dropping the ref should be sufficient } } // of top-level groups iteration - + + // drop any references to AI objects with TACAN + flightgear::NavDataCache::instance()->clearDynamicPositioneds(); + FGRenderer* render = globals->get_renderer(); // needed or we crash in multi-threaded OSG mode render->getViewer()->stopThreading(); diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 7218a74d2..a220bba5a 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -1725,6 +1725,16 @@ void NavDataCache::abortTransaction() d->transactionAborted = true; } +void NavDataCache::clearDynamicPositioneds() +{ + std::for_each(d->cache.begin(), d->cache.end(), [](PositionedCache::value_type& v) { + if (v.second->type() == FGPositioned::MOBILE_TACAN) { + auto mobile = fgpositioned_cast<FGMobileNavRecord>(v.second); + mobile->clearVehicle(); + } + }); +} + FGPositionedRef NavDataCache::loadById(PositionedID rowid) { if (rowid < 1) { diff --git a/src/Navaids/NavDataCache.hxx b/src/Navaids/NavDataCache.hxx index 9282c238a..0ef4450be 100644 --- a/src/Navaids/NavDataCache.hxx +++ b/src/Navaids/NavDataCache.hxx @@ -336,6 +336,9 @@ public: class ThreadedGUISearchPrivate; std::unique_ptr<ThreadedGUISearchPrivate> d; }; + + void clearDynamicPositioneds(); + private: NavDataCache(); diff --git a/src/Navaids/navrecord.cxx b/src/Navaids/navrecord.cxx index 0dffadb05..e5fbbab57 100644 --- a/src/Navaids/navrecord.cxx +++ b/src/Navaids/navrecord.cxx @@ -166,6 +166,11 @@ const SGVec3d& FGMobileNavRecord::cart() const } //------------------------------------------------------------------------------ +void FGMobileNavRecord::clearVehicle() +{ + _vehicle_node.clear(); +} + void FGMobileNavRecord::updateVehicle() { _vehicle_node.clear(); diff --git a/src/Navaids/navrecord.hxx b/src/Navaids/navrecord.hxx index 1350e9bfc..6887603af 100644 --- a/src/Navaids/navrecord.hxx +++ b/src/Navaids/navrecord.hxx @@ -126,6 +126,11 @@ class FGMobileNavRecord: public FGNavRecord { public: + static bool isType(FGPositioned::Type ty) + { + return (ty == MOBILE_TACAN); + } + FGMobileNavRecord( PositionedID aGuid, Type type, const std::string& ident, @@ -142,7 +147,9 @@ class FGMobileNavRecord: void updateVehicle(); void updatePos(); - protected: + void clearVehicle(); + +protected: SGTimeStamp _last_vehicle_update; SGPropertyNode_ptr _vehicle_node; double _initial_elevation_ft; // Elevation as given in the config file