Skip to content

Commit 19c7787

Browse files
committed
Fixed segfault when handling many AI entities on testmaps/test_lotsaimps due to null root or children.
1 parent eb26858 commit 19c7787

2 files changed

Lines changed: 40 additions & 28 deletions

File tree

neo/d3xp/ai/AI_pathing.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -903,21 +903,27 @@ bool FindOptimalPath( const pathNode_t *root, const obstacle_t *obstacles, int n
903903
}
904904
}
905905

906-
if ( !pathToGoalExists ) {
907-
seekPos.ToVec2() = root->children[0]->pos;
908-
} else if ( !optimizedPathCalculated ) {
909-
OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
910-
seekPos.ToVec2() = optimizedPath[1];
911-
}
906+
if ( root != NULL ) {
907+
if ( !pathToGoalExists ) {
908+
if ( root->children[0] != NULL ) {
909+
seekPos.ToVec2() = root->children[0]->pos;
910+
} else {
911+
seekPos.ToVec2() = root->pos;
912+
}
913+
} else if ( !optimizedPathCalculated ) {
914+
OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
915+
seekPos.ToVec2() = optimizedPath[1];
916+
}
912917

913-
if ( ai_showObstacleAvoidance.GetBool() ) {
914-
idVec3 start, end;
915-
start.z = end.z = height + 4.0f;
916-
numPathPoints = OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
917-
for ( i = 0; i < numPathPoints-1; i++ ) {
918-
start.ToVec2() = optimizedPath[i];
919-
end.ToVec2() = optimizedPath[i+1];
920-
gameRenderWorld->DebugArrow( colorCyan, start, end, 1 );
918+
if ( ai_showObstacleAvoidance.GetBool() ) {
919+
idVec3 start, end;
920+
start.z = end.z = height + 4.0f;
921+
numPathPoints = OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
922+
for ( i = 0; i < numPathPoints-1; i++ ) {
923+
start.ToVec2() = optimizedPath[i];
924+
end.ToVec2() = optimizedPath[i+1];
925+
gameRenderWorld->DebugArrow( colorCyan, start, end, 1 );
926+
}
921927
}
922928
}
923929

neo/game/ai/AI_pathing.cpp

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -906,21 +906,27 @@ bool FindOptimalPath( const pathNode_t *root, const obstacle_t *obstacles, int n
906906
}
907907
}
908908

909-
if ( !pathToGoalExists ) {
910-
seekPos.ToVec2() = root->children[0]->pos;
911-
} else if ( !optimizedPathCalculated ) {
912-
OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
913-
seekPos.ToVec2() = optimizedPath[1];
914-
}
909+
if ( root != NULL ) {
910+
if ( !pathToGoalExists ) {
911+
if ( root->children[0] != NULL ) {
912+
seekPos.ToVec2() = root->children[0]->pos;
913+
} else {
914+
seekPos.ToVec2() = root->pos;
915+
}
916+
} else if ( !optimizedPathCalculated ) {
917+
OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
918+
seekPos.ToVec2() = optimizedPath[1];
919+
}
915920

916-
if ( ai_showObstacleAvoidance.GetBool() ) {
917-
idVec3 start, end;
918-
start.z = end.z = height + 4.0f;
919-
numPathPoints = OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
920-
for ( i = 0; i < numPathPoints-1; i++ ) {
921-
start.ToVec2() = optimizedPath[i];
922-
end.ToVec2() = optimizedPath[i+1];
923-
gameRenderWorld->DebugArrow( colorCyan, start, end, 1 );
921+
if ( ai_showObstacleAvoidance.GetBool() ) {
922+
idVec3 start, end;
923+
start.z = end.z = height + 4.0f;
924+
numPathPoints = OptimizePath( root, bestNode, obstacles, numObstacles, optimizedPath );
925+
for ( i = 0; i < numPathPoints-1; i++ ) {
926+
start.ToVec2() = optimizedPath[i];
927+
end.ToVec2() = optimizedPath[i+1];
928+
gameRenderWorld->DebugArrow( colorCyan, start, end, 1 );
929+
}
924930
}
925931
}
926932

0 commit comments

Comments
 (0)