From: Durk Talsma Date: Thu, 14 May 2015 16:15:30 +0000 (+0200) Subject: Fix bug when starting using the --parkpos option. Create a pointer to a ParkingAssign... X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=98682c0c68001395b27f11d479911bc52b9a400a;p=flightgear.git 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. --- diff --git a/src/ATC/atc_mgr.cxx b/src/ATC/atc_mgr.cxx index 416229ca7..1b3a4dc27 100644 --- a/src/ATC/atc_mgr.cxx +++ b/src/ATC/atc_mgr.cxx @@ -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; diff --git a/src/ATC/atc_mgr.hxx b/src/ATC/atc_mgr.hxx index 09d40197a..03d37690c 100644 --- a/src/ATC/atc_mgr.hxx +++ b/src/ATC/atc_mgr.hxx @@ -53,6 +53,7 @@ private: bool networkVisible; bool initSucceeded; SGPropertyNode_ptr trans_num; + ParkingAssignment *pk; public: FGATCManager(); diff --git a/src/Main/positioninit.cxx b/src/Main/positioninit.cxx index f3bac6f7e..6acbe2159 100644 --- a/src/Main/positioninit.cxx +++ b/src/Main/positioninit.cxx @@ -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; }