From 6bcf194874fe8af4a4e171a7607c0e3e23b43d6f Mon Sep 17 00:00:00 2001 From: Gustas <37534529+Punsho@users.noreply.github.com> Date: Sun, 8 May 2022 22:53:38 +0300 Subject: [PATCH] Add map update tracking to MapCache and fix crash when restarting a game --- OpenRA.Game/Game.cs | 11 +++++++++++ OpenRA.Game/Map/MapCache.cs | 22 +++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 1695325d92..4dc38c29c6 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -235,6 +235,17 @@ namespace OpenRA // Reseed the RNG so this isn't an exact repeat of the last game lobbyInfo.GlobalSettings.RandomSeed = CosmeticRandom.Next(); + // Note: the map may have been changed on disk outside the game, changing its UID. + // Use the updated UID if we have tracked the update instead of failing. + lobbyInfo.GlobalSettings.Map = ModData.MapCache.GetUpdatedMap(lobbyInfo.GlobalSettings.Map); + if (lobbyInfo.GlobalSettings.Map == null) + { + Disconnect(); + Ui.ResetAll(); + LoadShellMap(); + return; + } + var orders = new[] { Order.Command($"sync_lobby {lobbyInfo.Serialize()}"), diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 4543eebeef..86c3af351d 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -46,6 +46,7 @@ namespace OpenRA /// Event is not called when map is deleted /// public event Action MapUpdated = (oldUID, newUID) => { }; + readonly Dictionary mapUpdates = new Dictionary(); public MapCache(ModData modData) { @@ -125,7 +126,10 @@ namespace OpenRA previews[uid].UpdateFromMap(mapPackage, package, classification, modData.Manifest.MapCompatibility, mapGrid.Type); if (oldMap != uid) - MapUpdated(oldMap, uid); + { + if (oldMap != null) + mapUpdates.Add(oldMap, uid); + } } } } @@ -310,6 +314,22 @@ namespace OpenRA Log.Write("debug", "MapCache.LoadAsyncInternal ended"); } + public string GetUpdatedMap(string uid) + { + if (uid == null) + return null; + + while (this[uid].Status != MapStatus.Available) + { + if (mapUpdates.ContainsKey(uid)) + uid = mapUpdates[uid]; + else + return null; + } + + return uid; + } + public void CacheMinimap(MapPreview preview) { bool launchPreviewLoaderThread;