From 560f89b2976b26d9ea0a27d90db2908d658ba69b Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Fri, 6 Nov 2020 15:04:13 +0100 Subject: [PATCH] Fix AI crash when an entity is moved to an invalid grid (#2507) --- .../EntitySystems/AI/Pathfinding/PathfindingSystem.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/PathfindingSystem.cs b/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/PathfindingSystem.cs index 5bdbbbe9d3..78d3778c8a 100644 --- a/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/PathfindingSystem.cs +++ b/Content.Server/GameObjects/EntitySystems/AI/Pathfinding/PathfindingSystem.cs @@ -328,9 +328,16 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding return; } + var newGridId = moveEvent.NewPosition.GetGridId(_entityManager); + if (newGridId == GridId.Invalid) + { + HandleEntityRemove(moveEvent.Sender); + return; + } + // The pathfinding graph is tile-based so first we'll check if they're on a different tile and if we need to update. // If you get entities bigger than 1 tile wide you'll need some other system so god help you. - var newTile = _mapManager.GetGrid(moveEvent.NewPosition.GetGridId(_entityManager)).GetTileRef(moveEvent.NewPosition); + var newTile = _mapManager.GetGrid(newGridId).GetTileRef(moveEvent.NewPosition); if (oldNode == null || oldNode.TileRef == newTile) {