diff --git a/Barotrauma/BarotraumaClient/Source/Characters/AI/HumanAIController.cs b/Barotrauma/BarotraumaClient/Source/Characters/AI/HumanAIController.cs index 0cd62a1ad..07db87e3a 100644 --- a/Barotrauma/BarotraumaClient/Source/Characters/AI/HumanAIController.cs +++ b/Barotrauma/BarotraumaClient/Source/Characters/AI/HumanAIController.cs @@ -21,7 +21,7 @@ namespace Barotrauma public override void DebugDraw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch) { - if (selectedAiTarget != null) + if (selectedAiTarget?.Entity != null) { GUI.DrawLine(spriteBatch, new Vector2(Character.DrawPosition.X, -Character.DrawPosition.Y), diff --git a/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs b/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs index 11c42b50d..12491c615 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/AI/AITarget.cs @@ -31,12 +31,34 @@ namespace Barotrauma public Vector2 WorldPosition { - get { return Entity.WorldPosition; } + get + { + if (Entity == null) + { +#if DEBUG + DebugConsole.ThrowError("Attempted to access a removed AITarget\n" + Environment.StackTrace); +#endif + return Vector2.Zero; + } + + return Entity.WorldPosition; + } } public Vector2 SimPosition { - get { return Entity.SimPosition; } + get + { + if (Entity == null) + { +#if DEBUG + DebugConsole.ThrowError("Attempted to access a removed AITarget\n" + Environment.StackTrace); +#endif + return Vector2.Zero; + } + + return Entity.SimPosition; + } } public AITarget(Entity e)