Fixed "attempted to access a removed AITarget" errors in AIObjectiveIdle

This commit is contained in:
Joonas Rikkonen
2018-08-07 16:49:17 +03:00
parent 4aeaf93af8
commit 865b35c6cd
@@ -30,13 +30,8 @@ namespace Barotrauma
protected override void Act(float deltaTime) protected override void Act(float deltaTime)
{ {
var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager; var pathSteering = character.AIController.SteeringManager as IndoorsSteeringManager;
if (pathSteering == null) return;
if (pathSteering==null)
{
return;
}
if (character.AnimController.InWater) if (character.AnimController.InWater)
{ {
@@ -72,11 +67,11 @@ namespace Barotrauma
// - if reached the end of the path // - if reached the end of the path
// - if the target is unreachable // - if the target is unreachable
// - if the path requires going outside // - if the path requires going outside
if (pathSteering==null || (pathSteering.CurrentPath != null && if (pathSteering == null || (pathSteering.CurrentPath != null &&
(pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable || pathSteering.CurrentPath.HasOutdoorsNodes))) (pathSteering.CurrentPath.NextNode == null || pathSteering.CurrentPath.Unreachable || pathSteering.CurrentPath.HasOutdoorsNodes)))
{ {
//steer away from edges of the hull //steer away from edges of the hull
if (character.AnimController.CurrentHull!=null) if (character.AnimController.CurrentHull != null)
{ {
float leftDist = character.Position.X - character.AnimController.CurrentHull.Rect.X; float leftDist = character.Position.X - character.AnimController.CurrentHull.Rect.X;
float rightDist = character.AnimController.CurrentHull.Rect.Right - character.Position.X; float rightDist = character.AnimController.CurrentHull.Rect.Right - character.Position.X;
@@ -114,7 +109,12 @@ namespace Barotrauma
return; return;
} }
if (currentTarget == null) return; if (currentTarget?.Entity == null) return;
if (currentTarget.Entity.Removed)
{
currentTarget = null;
return;
}
character.AIController.SteeringManager.SteeringSeek(currentTarget.SimPosition, 2.0f); character.AIController.SteeringManager.SteeringSeek(currentTarget.SimPosition, 2.0f);
} }