Don't crash when departure / destination runways don't exist

This commit is contained in:
Tobias Dammers 2022-08-31 12:17:04 +02:00
parent 3fc1c6363a
commit 74b3a057ad

View File

@ -182,8 +182,13 @@ var toFlightplan = func (ofp, fp=nil) {
fp.insertWaypoints(wps, 1); fp.insertWaypoints(wps, 1);
if (getprop('/sim/simbrief/options/import-departure') or 0) { if (getprop('/sim/simbrief/options/import-departure') or 0) {
departureRunwayID = ofp.getNode('origin').getValue('plan_rwy'); departureRunwayID = ofp.getNode('origin').getValue('plan_rwy');
logprint(2, sprintf("Trying to select departure: %s / %s", sidID, departureRunwayID)); logprint(2, sprintf("Trying to select departure: %s / %s", sidID or 'NONE', departureRunwayID));
if (!contains(departures[0].runways, departureRunwayID)) {
logprint(4, sprintf("Runway not found: %s", departureRunwayID));
}
else {
fp.departure_runway = departures[0].runways[departureRunwayID]; fp.departure_runway = departures[0].runways[departureRunwayID];
}
if (sidID != nil) { if (sidID != nil) {
fp.sid = departures[0].getSid(sidID); fp.sid = departures[0].getSid(sidID);
if (fp.sid == nil) if (fp.sid == nil)
@ -196,7 +201,12 @@ var toFlightplan = func (ofp, fp=nil) {
if (getprop('/sim/simbrief/options/import-arrival') or 0) { if (getprop('/sim/simbrief/options/import-arrival') or 0) {
destinationRunwayID = ofp.getNode('destination').getValue('plan_rwy'); destinationRunwayID = ofp.getNode('destination').getValue('plan_rwy');
printf("Trying to select arrival: %s / %s", starID, destinationRunwayID); printf("Trying to select arrival: %s / %s", starID, destinationRunwayID);
if (!contains(destinations[0].runways, destinationRunwayID)) {
logprint(4, sprintf("Runway not found: %s", destinationRunwayID));
}
else {
fp.destination_runway = destinations[0].runways[destinationRunwayID]; fp.destination_runway = destinations[0].runways[destinationRunwayID];
}
if (starID != nil) { if (starID != nil) {
fp.star = destinations[0].getStar(starID); fp.star = destinations[0].getStar(starID);
if (fp.star == nil) if (fp.star == nil)