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
This commit is contained in:
parent
35d3807904
commit
effc7049a2
@ -605,7 +605,7 @@ void QuadGraph::computeDistanceFromStart(unsigned int node, float new_distance)
|
||||
if(current_distance<new_distance)
|
||||
{
|
||||
float delta = new_distance - current_distance;
|
||||
updateDistancesForAllSuccessors(gn->getQuadIndex(), 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.getNumberOfSuccessors(); i++)
|
||||
@ -653,7 +665,8 @@ void QuadGraph::updateDistancesForAllSuccessors(unsigned int indx, float delta)
|
||||
if(g.getDistanceFromStart()+g.getDistanceToSuccessor(i) >
|
||||
g_next.getDistanceFromStart())
|
||||
{
|
||||
updateDistancesForAllSuccessors(g.getSuccessor(i), delta);
|
||||
updateDistancesForAllSuccessors(g.getSuccessor(i), delta,
|
||||
recursive_count);
|
||||
}
|
||||
}
|
||||
} // updateDistancesForAllSuccessors
|
||||
|
@ -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();
|
||||
// ----------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user