1
0
Fork 0

Fix bug when starting using the --parkpos option. Create a pointer to a ParkingAssignment object, so that the reference counter doesn't get reset to 0 when the local class is destroyed.

This commit is contained in:
Durk Talsma 2015-05-14 18:15:30 +02:00
parent 8ffbca1b58
commit 98682c0c68
3 changed files with 33 additions and 19 deletions

View file

@ -42,7 +42,7 @@ FGATCManager::FGATCManager() {
}
FGATCManager::~FGATCManager() {
delete pk;
}
void FGATCManager::init() {
@ -105,10 +105,11 @@ void FGATCManager::init() {
FGAirport *apt = FGAirport::findByIdent(airport);
if (apt && onGround) {// && !runway.empty()) {
FGAirportDynamics* dcs = apt->getDynamics();
ParkingAssignment pk(dcs->getParkingByName(parking));
pk = new ParkingAssignment(dcs->getParkingByName(parking));
// No valid parking location, so either at the runway or at a random location.
if (pk.isValid()) {
if (pk->isValid()) {
dcs->setParkingAvailable(pk->parking()->guid(), false);
fp = new FGAIFlightPlan;
controller = apt->getDynamics()->getStartupController();
int stationFreq = apt->getDynamics()->getGroundFrequency(1);
@ -120,11 +121,11 @@ void FGATCManager::init() {
leg = 1;
//double, lat, lon, head; // Unused variables;
//int getId = apt->getDynamics()->getParking(gateId, &lat, &lon, &head);
aircraftRadius = pk.parking()->getRadius();
string fltType = pk.parking()->getType(); // gate / ramp, ga, etc etc.
aircraftRadius = pk->parking()->getRadius();
string fltType = pk->parking()->getType(); // gate / ramp, ga, etc etc.
string aircraftType; // Unused.
string airline; // Currently used for gate selection, but a fallback mechanism will apply when not specified.
fp->setGate(pk);
fp->setGate(*pk);
if (!(fp->createPushBack(&ai_ac,
false,
apt,
@ -208,16 +209,17 @@ void FGATCManager::update ( double time ) {
//cerr << "Shutting down the atc_mgr" << endl;
return;
}
//cerr << "Size of waypoint cue " << size << " ";
//for (int i = 0; i < size; i++) {
// int val = fp->getRouteIndex(i);
//cerr << fp->getWayPoint(i)->getName() << " ";
// Test code: Print how far we're progressing along the taxi route.
//std::cerr << "Size of waypoint cue " << size << " ";
for (int i = 0; i < size; i++) {
int val = fp->getRouteIndex(i);
//std::cerr << fp->getWayPoint(i)->getName() << " ";
//if ((val) && (val != pos)) {
//intentions.push_back(val);
//cerr << "[done ] " << endl;
// intentions.push_back(val);
// std::cerr << "[done ] " << std::endl;
//}
//}
//cerr << "[done ] " << endl;
}
//std::cerr << "[done ] " << std::endl;
}
if (fp) {
//cerr << "Currently at leg : " << fp->getLeg() << endl;

View file

@ -53,6 +53,7 @@ private:
bool networkVisible;
bool initSucceeded;
SGPropertyNode_ptr trans_num;
ParkingAssignment *pk;
public:
FGATCManager();

View file

@ -183,6 +183,10 @@ static bool setPosFromAirportIDandHdg( const string& id, double tgt_hdg ) {
// Set current_options lon/lat given an airport id and parkig position name
static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& parkpos )
{
string fltType;
string acOperator;
string acType; // Currently not used by findAvailable parking, so safe to leave empty.
SGPath acData;
if ( id.empty() )
return false;
@ -202,9 +206,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
ParkingAssignment pka;
double radius = fgGetDouble("/sim/dimensions/radius-m");
if ((parkpos == string("AVAILABLE")) && (radius > 0)) {
string fltType;
string acOperator;
SGPath acData;
try {
acData = globals->get_fg_home();
acData.append("aircraft-data");
@ -232,9 +234,10 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
acOperator = fgGetString("/sim/aircraft-operator" );
}
string acType; // Currently not used by findAvailable parking, so safe to leave empty.
pka = dcs->getAvailableParking(radius, fltType, acType, acOperator);
if (pka.isValid()) {
// why is the following line necessary?
fgGetString("/sim/presets/parkpos");
fgSetString("/sim/presets/parkpos", pka.parking()->getName());
} else {
@ -243,6 +246,7 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
return false;
}
} else {
pka = dcs->getParkingByName(parkpos);
if (!pka.isValid()) {
SG_LOG( SG_GENERAL, SG_ALERT,
@ -250,7 +254,14 @@ static bool fgSetPosFromAirportIDandParkpos( const string& id, const string& par
return false;
}
}
// Why is the following line necessary?
fgGetString("/sim/presets/parkpos");
fgSetString("/sim/presets/parkpos", pka.parking()->getName());
// The problem is, this line doesn't work because the ParkingAssignment's refcounting mechanism:
// The parking will be released after this function returns.
// As a temporary measure, I'll try to reserve the parking via the atc_manager, which should work, because it uses the same
// mechanism as the AI traffic code.
dcs->setParkingAvailable(pka.parking()->guid(), false);
fgApplyStartOffset(pka.parking()->geod(), pka.parking()->getHeading());
return true;
}