]> git.mxchange.org Git - flightgear.git/commitdiff
Bugfix of problem reported by Mathias Fröhlich: Ground network trace()
authordurk <durk>
Wed, 16 Aug 2006 09:58:26 +0000 (09:58 +0000)
committerdurk <durk>
Wed, 16 Aug 2006 09:58:26 +0000 (09:58 +0000)
algorithm caused a program crash. Because there is always one waypoint more
than there are routes, the trace function should only pop_back the final route
entry at search depths of one or higher. I also added a lot of of additional
safeguarding code, due to the fact that the new trace algorithm was
apparently not as stable as I'd hoped it would be. ...

src/Airports/groundnetwork.cxx
src/Airports/groundnetwork.hxx

index 54942d02440e0b1a814a837b84021261f55c153d..862c359df79a483d95429610257c371a50210778 100644 (file)
@@ -133,9 +133,10 @@ bool FGTaxiRoute::next(int *nde, int *rte)
   //  cerr << "true" << endl;
   //else
   //  cerr << "false" << endl;
-  //if (nodes.size() != (routes.size()) +1)
-  //  cerr << "ALERT: Misconfigured TaxiRoute : " << nodes.size() << " " << routes.size() << endl;
-      
+  if (nodes.size() != (routes.size()) +1) {
+    SG_LOG(SG_GENERAL, SG_ALERT, "ALERT: Misconfigured TaxiRoute : " << nodes.size() << " " << routes.size());
+    exit(1);
+  }
   if (currNode == nodes.end())
     return false;
   *nde = *(currNode); 
@@ -288,6 +289,12 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(int start, int end)
 
 void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double distance)
 {
+  // Just check some preconditions of the trace algorithm
+  if (nodesStack.size() != routesStack.size()) 
+    {
+      SG_LOG(SG_GENERAL, SG_ALERT, "size of nodesStack and routesStack is not equal. NodesStack :" 
+            << nodesStack.size() << ". RoutesStack : " << routesStack.size());
+    }
   nodesStack.push_back(currNode->getIndex());
   totalDistance += distance;
   //cerr << "Starting trace " << depth << " total distance: " << totalDistance<< endl;
@@ -299,6 +306,10 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
     {
       //cerr << "Found route : " <<  totalDistance << "" << " " << *(nodesStack.end()-1) << endl;
       routes.push_back(FGTaxiRoute(nodesStack,routesStack,totalDistance));
+      if (nodesStack.empty() || routesStack.empty())
+       {
+         printRoutingError(string("while finishing route"));
+       }
       nodesStack.pop_back();
       routesStack.pop_back();
       if (!(foundRoute))
@@ -327,6 +338,10 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
       i++;
     }
     if (i != nodesStack.end()-1) {
+      if (nodesStack.empty() || routesStack.empty())
+       {
+         printRoutingError(string("while returning from an already encountered node"));
+       }
       nodesStack.pop_back();
       routesStack.pop_back();
       totalDistance -= distance;
@@ -338,6 +353,10 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
     if ((totalDistance > maxDistance) && foundRoute)
       {
        //cerr << "Stopping rediculously long trace: " << totalDistance << endl;
+       if (nodesStack.empty() || routesStack.empty())
+       {
+         printRoutingError(string("while returning from finding a rediculously long route"));
+       }
        nodesStack.pop_back();
        routesStack.pop_back();
        totalDistance -= distance;
@@ -368,11 +387,37 @@ void FGGroundNetwork::trace(FGTaxiNode *currNode, int end, int depth, double dis
     }
   else
     {
-      SG_LOG( SG_GENERAL, SG_DEBUG, "4" );
+      //SG_LOG( SG_GENERAL, SG_DEBUG, "4" );
+    }
+  if (nodesStack.empty())
+    {
+      printRoutingError(string("while finishing trace"));
     }
   nodesStack.pop_back();
-  routesStack.pop_back();
+  // Make sure not to dump the level-zero routesStack entry, because that was never created.
+  if (depth)
+    {
+      routesStack.pop_back();
+      //cerr << "leaving trace " << routesStack.size() << endl;
+    }
   totalDistance -= distance;
   return;
 }
 
+void FGGroundNetwork::printRoutingError(string mess)
+{
+  SG_LOG(SG_GENERAL, SG_ALERT,  "Error in ground network trace algorithm " << mess);
+  if (nodesStack.empty())
+    {
+      SG_LOG(SG_GENERAL, SG_ALERT, " nodesStack is empty. Dumping routesStack");
+      for (intVecIterator i = routesStack.begin() ; i != routesStack.end(); i++)
+       SG_LOG(SG_GENERAL, SG_ALERT, "Route " << (*i));
+    }
+  if (routesStack.empty())
+    {
+      SG_LOG(SG_GENERAL, SG_ALERT, " routesStack is empty. Dumping nodesStack"); 
+      for (intVecIterator i = nodesStack.begin() ; i != nodesStack.end(); i++)
+       SG_LOG(SG_GENERAL, SG_ALERT, "Node " << (*i));
+    }
+  //exit(1);
+}
index a67eb7266fa73d76ed5d581198e23a0c38cae133..4c8bdb2eb6d1a504fd4d53e5e872b7009fb9c1ae 100644 (file)
@@ -161,6 +161,8 @@ private:
   
   bool foundRoute;
   double totalDistance, maxDistance;
+
+  void printRoutingError(string);
   
 public:
   FGGroundNetwork();