From 3e7665146a4f6948300aaf29ce034e886723a0df Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 3 Jan 2021 23:40:24 +0000 Subject: [PATCH] Avoid BuildUnit crash if the item is invalidated before the task runs. --- OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs index ca4642bec4..09df74d13d 100644 --- a/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs +++ b/OpenRA.Mods.Common/Traits/Player/ProductionQueue.cs @@ -412,8 +412,11 @@ namespace OpenRA.Mods.Common.Traits var hasPlayedSound = false; BeginProduction(new ProductionItem(this, order.TargetString, cost, playerPower, () => self.World.AddFrameEndTask(_ => { - var isBuilding = unit.HasTraitInfo(); + // Make sure the item hasn't been invalidated between the ProductionItem ticking and this FrameEndTask running + if (!Queue.Any(i => i.Done && i.Item == unit.Name)) + return; + var isBuilding = unit.HasTraitInfo(); if (isBuilding && !hasPlayedSound) hasPlayedSound = Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName); else if (!isBuilding)