Fix for exceptions when a human is targeting a removed entity while debugdraw is enabled, accessing AITarget position properties after the target has been destroyed doesn't throw an exception (but does log an error in debug builds).

This commit is contained in:
Joonas Rikkonen
2017-08-13 20:00:52 +03:00
parent 4d40f5d483
commit c7a357d84c
2 changed files with 25 additions and 3 deletions

View File

@@ -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),

View File

@@ -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)