Skip to content

Commit

Permalink
Fix InstantHit crashing if blockable and target is dead
Browse files Browse the repository at this point in the history
If the weapon has TargetActorCenter, the projectile is Blockable
and the target dies the same tick the projectile is fired but before
the 'blocked' check is performed, the target.CenterPosition lookup
would crash since the target has become invalid.

Work around this by ignoring TargetActorCenter and using
args.PassiveTarget position instead if the target is already dead.
  • Loading branch information
reaperrr committed Jul 6, 2019
1 parent b4b3ce6 commit 6270a12
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions OpenRA.Mods.Common/Projectiles/InstantHit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ public void Tick(World world)
{
// Check for blocking actors
WPos blockedPos;
if (info.Blockable && BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition,
info.Width, out blockedPos))
if (info.Blockable)
{
target = Target.FromPos(blockedPos);
// If GuidedTarget has become invalid due to getting killed the same tick,
// we need to set target to args.PassiveTarget to prevent target.CenterPosition below from crashing.
// The warheads have target validity checks themselves so they don't need this, but AnyBlockingActorsBetween does.
if (target.Type == TargetType.Invalid)
target = Target.FromPos(args.PassiveTarget);

if (BlocksProjectiles.AnyBlockingActorsBetween(world, args.Source, target.CenterPosition,
info.Width, out blockedPos))
target = Target.FromPos(blockedPos);
}

args.Weapon.Impact(target, args.SourceActor, args.DamageModifiers);
Expand Down

0 comments on commit 6270a12

Please sign in to comment.