]> git.mxchange.org Git - flightgear.git/commitdiff
Make TrafficRecord own its AIAircraft.
authorJames Turner <zakalawe@mac.com>
Mon, 4 Jan 2016 18:10:04 +0000 (12:10 -0600)
committerJames Turner <zakalawe@mac.com>
Mon, 4 Jan 2016 19:34:39 +0000 (13:34 -0600)
- use the ref-counting system, hopefully avoid a dangling pointer
  crash I encountered. (Of course it may turn into a leak)

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

index 1b32bde4ad392010a6631c9dc5fd6eafa6c998a6..355eebe26bfe25e2aa5501ca848e54e26449e821 100644 (file)
@@ -195,8 +195,7 @@ void FGATCManager::init() {
 
 void FGATCManager::shutdown()
 {
-    delete ai_ac;
-    ai_ac = NULL;
+    ai_ac.clear();
     activeStations.clear();
 }
 
index 7091ed778b9968520050efab6e3dd39e203c6ef3..b8d728acd4ee24aab6569073daf9c842dbb0fba9 100644 (file)
@@ -46,7 +46,7 @@ class FGATCManager : public SGSubsystem
 {
 private:
   AtcVec activeStations;
-  FGAIAircraft* ai_ac;
+  SGSharedPtr<FGAIAircraft> ai_ac;
   FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft. 
   bool networkVisible;
   bool initSucceeded;
index f27ca86a1f1c663d798284751f2a175a030d7be0..d2fc499e9acf1f1877946c225e20c08d80c1d780 100644 (file)
@@ -180,8 +180,11 @@ FGTrafficRecord::FGTrafficRecord():
         allowPushback(true),
         priority(0),
         timer(0),
-        latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0),
-        aircraft(NULL)
+        latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0)
+{
+}
+
+FGTrafficRecord::~FGTrafficRecord()
 {
 }
 
@@ -208,6 +211,17 @@ void FGTrafficRecord::setPositionAndIntentions(int pos,
         }
     }
 }
+
+void FGTrafficRecord::setAircraft(FGAIAircraft *ref)
+{
+    aircraft = ref;
+}
+
+FGAIAircraft* FGTrafficRecord::getAircraft() const
+{
+    return aircraft.ptr();
+}
+
 /**
  * Check if another aircraft is ahead of the current one, and on the same
  * return true / false is the is/isn't the case.
index bdedf0e1e902b57d6c45f95ac5794835512ba07c..bbbc78539d033b9622335d6d7737567a17205e3f 100644 (file)
@@ -161,12 +161,12 @@ private:
     FGATCInstruction instruction;
     double latitude, longitude, heading, speed, altitude, radius;
     std::string runway;
-    //FGAISchedule *trafficRef;
-    FGAIAircraft *aircraft;
+    SGSharedPtr<FGAIAircraft> aircraft;
 
 
 public:
     FGTrafficRecord();
+    virtual ~FGTrafficRecord();
 
     void setId(int val)  {
         id = val;
@@ -266,17 +266,15 @@ public:
         return runway;
     };
     //void setCallSign(string clsgn) { callsign = clsgn; };
-    void setAircraft(FGAIAircraft *ref) {
-        aircraft = ref;
-    };
+    void setAircraft(FGAIAircraft *ref);
+
     void updateState() {
         state++;
         allowTransmission=true;
     };
     //string getCallSign() { return callsign; };
-    FGAIAircraft *getAircraft() const {
-        return aircraft;
-    };
+    FGAIAircraft *getAircraft() const;
+
     int getTime() const {
         return timer;
     };