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:
@@ -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),
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user