Fix crash when carryall cargo is killed on same tick as pickup.

This commit is contained in:
Paul Chote
2017-04-08 12:58:18 +01:00
parent 737764a47a
commit 043d7587a6

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual object Create(ActorInitializer init) { return new Carryall(init.Self, this); } public virtual object Create(ActorInitializer init) { return new Carryall(init.Self, this); }
} }
public class Carryall : INotifyKilled, ISync, IRender, INotifyActorDisposing, IIssueOrder, IResolveOrder, IOrderVoice public class Carryall : INotifyKilled, ISync, ITick, IRender, INotifyActorDisposing, IIssueOrder, IResolveOrder, IOrderVoice
{ {
public enum CarryallState public enum CarryallState
{ {
@@ -68,7 +68,7 @@ namespace OpenRA.Mods.Common.Traits
public Carryall(Actor self, CarryallInfo info) public Carryall(Actor self, CarryallInfo info)
{ {
this.Info = info; Info = info;
Carryable = null; Carryable = null;
State = CarryallState.Idle; State = CarryallState.Idle;
@@ -79,6 +79,13 @@ namespace OpenRA.Mods.Common.Traits
facing = self.Trait<IFacing>(); facing = self.Trait<IFacing>();
} }
void ITick.Tick(Actor self)
{
// Cargo may be killed in the same tick as, but after they are attached
if (Carryable != null && Carryable.IsDead)
DetachCarryable(self);
}
void INotifyActorDisposing.Disposing(Actor self) void INotifyActorDisposing.Disposing(Actor self)
{ {
if (State == CarryallState.Carrying) if (State == CarryallState.Carrying)
@@ -156,7 +163,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr) IEnumerable<IRenderable> IRender.Render(Actor self, WorldRenderer wr)
{ {
if (State == CarryallState.Carrying) if (State == CarryallState.Carrying && !Carryable.IsDead)
{ {
if (carryablePreview == null) if (carryablePreview == null)
{ {