From e06e9ccd1e69adc732dc7139af5aa4b490acf904 Mon Sep 17 00:00:00 2001 From: durk Date: Wed, 16 Aug 2006 09:58:26 +0000 Subject: [PATCH] =?utf8?q?Bugfix=20of=20problem=20reported=20by=20Mathias?= =?utf8?q?=20Fr=C3=B6hlich:=20Ground=20network=20trace()=20algorithm=20cau?= =?utf8?q?sed=20a=20program=20crash.=20Because=20there=20is=20always=20one?= =?utf8?q?=20waypoint=20more=20than=20there=20are=20routes,=20the=20trace?= =?utf8?q?=20function=20should=20only=20pop=5Fback=20the=20final=20route?= =?utf8?q?=20entry=20at=20search=20depths=20of=20one=20or=20higher.=20I=20?= =?utf8?q?also=20added=20a=20lot=20of=20of=20additional=20safeguarding=20c?= =?utf8?q?ode,=20due=20to=20the=20fact=20that=20the=20new=20trace=20algori?= =?utf8?q?thm=20was=20apparently=20not=20as=20stable=20as=20I'd=20hoped=20?= =?utf8?q?it=20would=20be.=20...?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/Airports/groundnetwork.cxx | 55 ++++++++++++++++++++++++++++++---- src/Airports/groundnetwork.hxx | 2 ++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 54942d024..862c359df 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -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); +} diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index a67eb7266..4c8bdb2eb 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -161,6 +161,8 @@ private: bool foundRoute; double totalDistance, maxDistance; + + void printRoutingError(string); public: FGGroundNetwork(); -- 2.39.5