From 3b1f4ba07f55098166879449dfd7a9ebcd7d0d4a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 27 Nov 2020 22:36:11 +0000 Subject: [PATCH] Fix production exit desync. --- OpenRA.Mods.Common/Traits/Buildings/Exit.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Traits/Buildings/Exit.cs b/OpenRA.Mods.Common/Traits/Buildings/Exit.cs index 48b3926866..0169fb5bac 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Exit.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Exit.cs @@ -48,9 +48,14 @@ namespace OpenRA.Mods.Common.Traits { public static Exit NearestExitOrDefault(this Actor actor, WPos pos, string productionType = null, Func p = null) { + // The .ToList() is required to work around a bug/unexpected behaviour in mono, where + // the ThenBy clause makes the FirstOrDefault behave differently than under .NET. + // This is important because p may have side-effects that trigger a desync if not + // called on the same exits in the same order! var all = Exits(actor, productionType) .OrderBy(e => e.Info.Priority) - .ThenBy(e => (actor.CenterPosition + e.Info.SpawnOffset - pos).Length); + .ThenBy(e => (actor.CenterPosition + e.Info.SpawnOffset - pos).Length) + .ToList(); return p != null ? all.FirstOrDefault(p) : all.FirstOrDefault(); }