]> git.mxchange.org Git - flightgear.git/commitdiff
Fix a possible crash
authordaveluff <daveluff>
Tue, 16 Mar 2004 10:35:29 +0000 (10:35 +0000)
committerdaveluff <daveluff>
Tue, 16 Mar 2004 10:35:29 +0000 (10:35 +0000)
src/ATC/tower.cxx

index 10f35cb3aceeaf4e078c5e30633c33b3e422aaf6..a9e2ba709b6367d8dcd3c4dc9b112939274b4a31 100644 (file)
@@ -599,17 +599,19 @@ void FGTower::ProcessDownwindReport(TowerPlaneRec* t) {
        int a = 0;      // Count of preceding planes on approach
        bool cf = false;        // conflicting traffic on final
        bool cc = false;        // preceding traffic in circuit
+       TowerPlaneRec* tc;
        for(tower_plane_rec_list_iterator twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
                if((*twrItr)->plane.callsign == responseID) break;
+               tc = *twrItr;
                ++i;
        }
        if(i > 1) { cc = true; }
        doThresholdETACalc();
-       TowerPlaneRec* tt;
+       TowerPlaneRec* tf;
        for(tower_plane_rec_list_iterator twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
                if((*twrItr)->eta < (t->eta + 45)) {
                        a++;
-                       tt = *twrItr;
+                       tf = *twrItr;
                        cf = true;
                        // This should set the flagged plane to be the last conflicting one, and hence the one to follow.
                        // It ignores the fact that we might have problems slotting into the approach traffic behind it - 
@@ -621,11 +623,23 @@ void FGTower::ProcessDownwindReport(TowerPlaneRec* t) {
        trns += ConvertNumToSpokenDigits(i + a);
        // This assumes that the number spoken is landing position, not circuit position, since some of the traffic might be on straight-in final.
        trns += " ";
+       TowerPlaneRec* tt;
        if((i == 1) && (!rwyList.size()) && (t->nextOnRwy) && (!cf)) {  // Unfortunately nextOnRwy currently doesn't handle circuit/straight-in ordering properly at present, hence the cf check below.
                trns += "Cleared to land";      // TODO - clear for the option if appropriate
                t->clearedToLand = true;
                if(!t->isUser) t->planePtr->RegisterTransmission(7);
        } else if((i+a) > 1) {
+               //First set tt to point to the correct preceding plane - final or circuit
+               if(i > 1 && a > 0) {
+                       tt = (tf->eta < tc->eta ? tf : tc);
+               } else if(i > 1) {
+                       tt = tc;
+               } else if(a > 0) {
+                       tt = tf;
+               } else {
+                       // We should never get here!
+                       SG_LOG(SG_ATC, SG_ALERT, "ALERT - Logic error in FGTower::ProcessDownwindReport");
+               }
                trns += "Follow the ";
                string s = tt->plane.callsign;
                int p = s.find('-');