Skip to content

Commit

Permalink
Gracefully handle trying to find paths outside the map.
Browse files Browse the repository at this point in the history
Rather than crashing, return no path instead.
  • Loading branch information
RoosterDragon committed Apr 26, 2022
1 parent 135823f commit 0b136d4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions OpenRA.Mods.Common/Traits/World/PathFinder.cs
Expand Up @@ -62,6 +62,7 @@ public PathFinder(World world)

// If the target cell is inaccessible, bail early.
var inaccessible =
!world.Map.Contains(target) ||
!locomotor.CanMoveFreelyInto(self, target, check, ignoreActor) ||
(!(customCost is null) && customCost(target) == PathGraph.PathCostForInvalidPath);
if (inaccessible)
Expand All @@ -74,7 +75,11 @@ public PathFinder(World world)

// For adjacent cells on the same layer, we can return the path without invoking a full search.
if (source.Layer == target.Layer && (source - target).LengthSquared < 3)
{
if (!world.Map.Contains(source))
return NoPath;
return new List<CPos>(2) { target, source };
}

// With one starting point, we can use a bidirectional search.
using (var fromTarget = PathSearch.ToTargetCell(
Expand Down

0 comments on commit 0b136d4

Please sign in to comment.