Avoid BuildUnit crash if the item is invalidated before the task runs.

This commit is contained in:
Paul Chote
2021-01-03 23:40:24 +00:00
committed by reaperrr
parent 16d0f8a5a6
commit 3e7665146a

View File

@@ -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<BuildingInfo>();
// 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<BuildingInfo>();
if (isBuilding && !hasPlayedSound)
hasPlayedSound = Game.Sound.PlayNotification(rules, self.Owner, "Speech", Info.ReadyAudio, self.Owner.Faction.InternalName);
else if (!isBuilding)