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:
parent
359f924ec9
commit
fadad5d70b
4 changed files with 24 additions and 13 deletions
|
@ -195,8 +195,7 @@ void FGATCManager::init() {
|
|||
|
||||
void FGATCManager::shutdown()
|
||||
{
|
||||
delete ai_ac;
|
||||
ai_ac = NULL;
|
||||
ai_ac.clear();
|
||||
activeStations.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue