1
0
Fork 0

Make TrafficRecord own its AIAircraft.

- use the ref-counting system, hopefully avoid a dangling pointer
  crash I encountered. (Of course it may turn into a leak)
This commit is contained in:
James Turner 2016-01-04 12:10:04 -06:00
parent 359f924ec9
commit fadad5d70b
4 changed files with 24 additions and 13 deletions

View file

@ -195,8 +195,7 @@ void FGATCManager::init() {
void FGATCManager::shutdown() void FGATCManager::shutdown()
{ {
delete ai_ac; ai_ac.clear();
ai_ac = NULL;
activeStations.clear(); activeStations.clear();
} }

View file

@ -46,7 +46,7 @@ class FGATCManager : public SGSubsystem
{ {
private: private:
AtcVec activeStations; AtcVec activeStations;
FGAIAircraft* ai_ac; SGSharedPtr<FGAIAircraft> ai_ac;
FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft. FGATCController *controller, *prevController; // The ATC controller that is responsible for the user's aircraft.
bool networkVisible; bool networkVisible;
bool initSucceeded; bool initSucceeded;

View file

@ -180,8 +180,11 @@ FGTrafficRecord::FGTrafficRecord():
allowPushback(true), allowPushback(true),
priority(0), priority(0),
timer(0), timer(0),
latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0), latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0)
aircraft(NULL) {
}
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 * Check if another aircraft is ahead of the current one, and on the same
* return true / false is the is/isn't the case. * return true / false is the is/isn't the case.

View file

@ -161,12 +161,12 @@ private:
FGATCInstruction instruction; FGATCInstruction instruction;
double latitude, longitude, heading, speed, altitude, radius; double latitude, longitude, heading, speed, altitude, radius;
std::string runway; std::string runway;
//FGAISchedule *trafficRef; SGSharedPtr<FGAIAircraft> aircraft;
FGAIAircraft *aircraft;
public: public:
FGTrafficRecord(); FGTrafficRecord();
virtual ~FGTrafficRecord();
void setId(int val) { void setId(int val) {
id = val; id = val;
@ -266,17 +266,15 @@ public:
return runway; return runway;
}; };
//void setCallSign(string clsgn) { callsign = clsgn; }; //void setCallSign(string clsgn) { callsign = clsgn; };
void setAircraft(FGAIAircraft *ref) { void setAircraft(FGAIAircraft *ref);
aircraft = ref;
};
void updateState() { void updateState() {
state++; state++;
allowTransmission=true; allowTransmission=true;
}; };
//string getCallSign() { return callsign; }; //string getCallSign() { return callsign; };
FGAIAircraft *getAircraft() const { FGAIAircraft *getAircraft() const;
return aircraft;
};
int getTime() const { int getTime() const {
return timer; return timer;
}; };