Add map update tracking to MapCache and fix crash when restarting a game
This commit is contained in:
@@ -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()}"),
|
||||
|
||||
@@ -46,6 +46,7 @@ namespace OpenRA
|
||||
/// Event is not called when map is deleted
|
||||
/// </summary>
|
||||
public event Action<string, string> MapUpdated = (oldUID, newUID) => { };
|
||||
readonly Dictionary<string, string> mapUpdates = new Dictionary<string, string>();
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user