From 628cc837ef56a9daae79cfa73231ae23a12c71cd Mon Sep 17 00:00:00 2001 From: dnqbob Date: Wed, 28 Jun 2023 21:28:31 +0800 Subject: [PATCH] Fix a crash when RallyPoint creates RallyPointIndicator --- .../Traits/Buildings/RallyPoint.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs index 52e5188121..90c50377e5 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/RallyPoint.cs @@ -58,16 +58,16 @@ namespace OpenRA.Mods.Common.Traits public override object Create(ActorInitializer init) { return new RallyPoint(init.Self, this); } } - public class RallyPoint : IIssueOrder, IResolveOrder, INotifyOwnerChanged, INotifyCreated + public class RallyPoint : IIssueOrder, IResolveOrder, INotifyOwnerChanged, INotifyCreated, INotifyAddedToWorld, INotifyRemovedFromWorld { const string OrderID = "SetRallyPoint"; + const uint ForceSet = 1; public List Path; public RallyPointInfo Info; public string PaletteName { get; private set; } - - const uint ForceSet = 1; + RallyPointIndicator effect; public void ResetPath(Actor self) { @@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits void INotifyCreated.Created(Actor self) { - self.World.Add(new RallyPointIndicator(self, this)); + effect = new RallyPointIndicator(self, this); } public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) @@ -138,6 +138,16 @@ namespace OpenRA.Mods.Common.Traits return order.OrderString == OrderID && order.ExtraData == ForceSet; } + void INotifyAddedToWorld.AddedToWorld(Actor self) + { + self.World.AddFrameEndTask(w => w.Add(effect)); + } + + void INotifyRemovedFromWorld.RemovedFromWorld(Actor self) + { + self.World.AddFrameEndTask(w => w.Remove(effect)); + } + sealed class RallyPointOrderTargeter : IOrderTargeter { readonly RallyPointInfo info;