]> git.mxchange.org Git - flightgear.git/commitdiff
Different fix for traffic shutdown crash.
authorJames Turner <zakalawe@mac.com>
Thu, 14 Apr 2016 17:54:52 +0000 (18:54 +0100)
committerJames Turner <zakalawe@mac.com>
Fri, 15 Apr 2016 15:26:54 +0000 (16:26 +0100)
Fix for: https://sourceforge.net/p/flightgear/codetickets/1864/

src/ATC/trafficcontrol.cxx
src/ATC/trafficcontrol.hxx

index 3b84411997b173d54b4a468c5a901d4130417edb..6b77890a0acc5d461ea85eb97c2c7fce92e53010 100644 (file)
@@ -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,
index bbbc78539d033b9622335d6d7737567a17205e3f..ab3432573aaf4de19c6ed9c0d0f76182c3563823 100644 (file)
@@ -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,