]> git.mxchange.org Git - flightgear.git/commitdiff
Prevent exceptions in getRunwayByIdent when a malformed rwyuse.xml means
authorjmt <jmt>
Tue, 6 Jan 2009 16:56:26 +0000 (16:56 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 7 Jan 2009 09:36:31 +0000 (10:36 +0100)
there is no valid active runway. This is not ideal, since it masks underlying
problems - the real fix is to make the runway-use code more robust and
validate input XML.

src/Airports/dynamics.cxx
src/Airports/dynamics.hxx

index 5f41b8d9ecfeb09571763c397e0f88ca06513b40..78927c820af39514de5017eae4a169ce4c6bc9f6 100644 (file)
@@ -348,26 +348,24 @@ void FGAirportDynamics::setRwyUse(const FGRunwayPreference& ref)
   //cerr << "Exiting due to not implemented yet" << endl;
   //exit(1);
 }
-void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, string &runway)
+
+bool FGAirportDynamics::innerGetActiveRunway(const string &trafficType, int action, string &runway)
 {
-  double windSpeed;
+double windSpeed;
   double windHeading;
   double maxTail;
   double maxCross;
   string name;
   string type;
 
-  if (!(rwyPrefs.available()))
-    {
-      runway = chooseRunwayFallback();
-      return; // generic fall back goes here
-    }
-  else
-    {
-      RunwayGroup *currRunwayGroup = 0;
-      int nrActiveRunways = 0;
-      time_t dayStart = fgGetLong("/sim/time/utc/day-seconds");
-      if ((abs((long)(dayStart - lastUpdate)) > 600) || trafficType != prevTrafficType)
+  if (!rwyPrefs.available()) {
+    return false;
+  }
+  
+  RunwayGroup *currRunwayGroup = 0;
+  int nrActiveRunways = 0;
+  time_t dayStart = fgGetLong("/sim/time/utc/day-seconds");
+  if ((abs((long)(dayStart - lastUpdate)) > 600) || trafficType != prevTrafficType)
        {
          landing.clear();
          takeoff.clear();
@@ -390,19 +388,19 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
          //cerr << "A"<< endl;
          currSched = rwyPrefs.getSchedule(trafficType.c_str());
          if (!(currSched))
-           return;
+           return false;
          //cerr << "B"<< endl;
          scheduleName = currSched->getName(dayStart);
          maxTail  = currSched->getTailWind  ();
          maxCross = currSched->getCrossWind ();
          //cerr << "SChedule anme = " << scheduleName << endl;
          if (scheduleName.empty())
-           return;
+           return false;
          //cerr << "C"<< endl;
          currRunwayGroup = rwyPrefs.getGroup(scheduleName); 
          //cerr << "D"<< endl;
          if (!(currRunwayGroup))
-           return;
+           return false;
          nrActiveRunways = currRunwayGroup->getNrActiveRunways();
 
         // Keep a history of the currently active runways, to ensure
@@ -451,7 +449,8 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
            }
           //cerr << endl;
        }
-      if (action == 1) // takeoff 
+  
+  if (action == 1) // takeoff 
        {
          int nr = takeoff.size();
          if (nr)
@@ -466,7 +465,8 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
              runway = chooseRunwayFallback();
            }
        } 
-      if (action == 2) // landing
+  
+  if (action == 2) // landing
        {
          int nr = landing.size();
          if (nr)
@@ -478,9 +478,16 @@ void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, s
               runway = chooseRunwayFallback();
            }
        } 
-      //runway = globals->get_runways()->search(_ap->getId(), int(windHeading));
-      //cerr << "Seleceted runway: " << runway << endl;
-    }
+
+  return true;
+}
+
+void FGAirportDynamics::getActiveRunway(const string &trafficType, int action, string &runway)
+{
+  bool ok = innerGetActiveRunway(trafficType, action, runway);
+  if (!ok) {
+    runway = chooseRunwayFallback();
+  }
 }
 
 string FGAirportDynamics::chooseRunwayFallback()
index f6e344932758447a2af8a60635ea2b64efd416aa..96d906b88e29253c8a541e9b795ab9645e2fd5fd 100644 (file)
@@ -72,7 +72,7 @@ private:
   //double avWindSpeed   [10];
 
   string chooseRunwayFallback();
-
+  bool innerGetActiveRunway(const string &trafficType, int action, string &runway);
 public:
   FGAirportDynamics(FGAirport* ap);
   FGAirportDynamics(const FGAirportDynamics &other);