From c15e4753ac22a8a003336fd3f75587eaf6ed1ca3 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 14 Apr 2016 18:54:52 +0100 Subject: [PATCH] Different fix for traffic shutdown crash. Fix for: https://sourceforge.net/p/flightgear/codetickets/1864/ --- src/ATC/trafficcontrol.cxx | 46 +++++++++++++++++++++++++++++++++++--- src/ATC/trafficcontrol.hxx | 9 +++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/ATC/trafficcontrol.cxx b/src/ATC/trafficcontrol.cxx index 3b8441199..6b77890a0 100644 --- a/src/ATC/trafficcontrol.cxx +++ b/src/ATC/trafficcontrol.cxx @@ -58,6 +58,30 @@ using std::string; using std::cout; using std::endl; +namespace { + +TrafficVectorIterator findTraffic(TrafficVector& vec, int id) +{ + TrafficVectorIterator it = vec.begin(); + for (; it != vec.end(); ++it) { + if (it->getId() == id) { + return it; + } + } + + return it; // vec.end, effectively +} + +void clearTrafficControllers(TrafficVector& vec) +{ + TrafficVectorIterator it = vec.begin(); + for (; it != vec.end(); ++it) { + it->getAircraft()->clearATCController(); + } +} + +} // of anonymous namespace + /*************************************************************************** * ActiveRunway **************************************************************************/ @@ -190,9 +214,6 @@ FGTrafficRecord::FGTrafficRecord(): FGTrafficRecord::~FGTrafficRecord() { - //if (aircraft) { - // aircraft->clearATCController(); - //} } void FGTrafficRecord::setPositionAndIntentions(int pos, @@ -828,6 +849,15 @@ FGTowerController::FGTowerController(FGAirportDynamics *par) : parent = par; } +FGTowerController::~FGTowerController() +{ + // to avoid the exception described in: + // https://sourceforge.net/p/flightgear/codetickets/1864/ + // we want to ensure AI aircraft signing-off is a no-op now + + clearTrafficControllers(activeTraffic); +} + // void FGTowerController::announcePosition(int id, FGAIFlightPlan * intendedRoute, @@ -1093,6 +1123,11 @@ FGStartupController::FGStartupController(FGAirportDynamics *par): parent = par; } +FGStartupController::~FGStartupController() +{ + clearTrafficControllers(activeTraffic); +} + void FGStartupController::announcePosition(int id, FGAIFlightPlan * intendedRoute, int currentPosition, double lat, @@ -1552,6 +1587,11 @@ FGApproachController::FGApproachController(FGAirportDynamics *par): parent = par; } +FGApproachController::~FGApproachController() +{ + clearTrafficControllers(activeTraffic); +} + // void FGApproachController::announcePosition(int id, FGAIFlightPlan * intendedRoute, diff --git a/src/ATC/trafficcontrol.hxx b/src/ATC/trafficcontrol.hxx index bbbc78539..ab3432573 100644 --- a/src/ATC/trafficcontrol.hxx +++ b/src/ATC/trafficcontrol.hxx @@ -462,7 +462,8 @@ private: public: FGTowerController(FGAirportDynamics *parent); - virtual ~FGTowerController() {}; + virtual ~FGTowerController(); + virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, double lat, double lon, double hdg, double spd, double alt, double radius, int leg, @@ -498,7 +499,8 @@ private: public: FGStartupController(FGAirportDynamics *parent); - virtual ~FGStartupController() {}; + virtual ~FGStartupController(); + virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, double lat, double lon, double hdg, double spd, double alt, double radius, int leg, @@ -538,7 +540,8 @@ private: public: FGApproachController(FGAirportDynamics * parent); - virtual ~FGApproachController() { }; + virtual ~FGApproachController(); + virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute, double lat, double lon, double hdg, double spd, double alt, double radius, int leg, -- 2.39.5