From effc7049a235ec2c878a5a41cb4c72f00f66b33b Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 24 Oct 2013 06:04:22 +0000 Subject: [PATCH] Avoid infinite recursion when a track with looped shortcuts is loaded. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@14300 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/tracks/quad_graph.cpp | 19 ++++++++++++++++--- src/tracks/quad_graph.hpp | 4 +++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/tracks/quad_graph.cpp b/src/tracks/quad_graph.cpp index 4c1e0dd31..d85b87c01 100644 --- a/src/tracks/quad_graph.cpp +++ b/src/tracks/quad_graph.cpp @@ -605,7 +605,7 @@ void QuadGraph::computeDistanceFromStart(unsigned int node, float new_distance) if(current_distancegetQuadIndex(), delta); + updateDistancesForAllSuccessors(gn->getQuadIndex(), delta, 0); } return; } @@ -634,9 +634,21 @@ void QuadGraph::computeDistanceFromStart(unsigned int node, float new_distance) * distance from start. * \param indx Index of the node for which to increase the distance. * \param delta Amount by which to increase the distance. + * \param recursive_count Counts how often this function was called + * recursively in order to catch incorrect graphs that contain loops. */ -void QuadGraph::updateDistancesForAllSuccessors(unsigned int indx, float delta) +void QuadGraph::updateDistancesForAllSuccessors(unsigned int indx, float delta, + unsigned int recursive_count) { + if(recursive_count>getNumNodes()) + { + Log::error("QuadGraph", + "Quad graph contains a loop (without start node)."); + Log::fatal("QuadGraph", + "Fix graph, check for directions of all shortcuts etc."); + } + recursive_count++; + GraphNode &g=getNode(indx); g.setDistanceFromStart(g.getDistanceFromStart()+delta); for(unsigned int i=0; i g_next.getDistanceFromStart()) { - updateDistancesForAllSuccessors(g.getSuccessor(i), delta); + updateDistancesForAllSuccessors(g.getSuccessor(i), delta, + recursive_count); } } } // updateDistancesForAllSuccessors diff --git a/src/tracks/quad_graph.hpp b/src/tracks/quad_graph.hpp index 7c8d5d805..228bbbf76 100644 --- a/src/tracks/quad_graph.hpp +++ b/src/tracks/quad_graph.hpp @@ -123,7 +123,9 @@ public: const video::SColor &fill_color =video::SColor(127, 255, 255, 255) ); void mapPoint2MiniMap(const Vec3 &xyz, Vec3 *out) const; - void updateDistancesForAllSuccessors(unsigned int indx, float delta); + void updateDistancesForAllSuccessors(unsigned int indx, + float delta, + unsigned int count); void setupPaths(); void computeChecklineRequirements(); // ----------------------------------------------------------------------