From cd1e9ecb291aee112b9fadcb3394429565d0c4fb Mon Sep 17 00:00:00 2001 From: BoroBongo Date: Sun, 22 Nov 2026 02:28:55 +0000 Subject: [PATCH] fix: an overwritten save slot shows its new screenshot in the save/load menu The menu took the thumbnail from TextureCacheService's static cache keyed by "savegame_" + title. Overwriting a slot under the same name (or two slots with the same or an empty name) returned the old texture until the game was restarted. Each slot now builds its own thumbnail from its THUMB.SAV, and the textures are destroyed whenever the slots are read again (after every save, when the menu opens) and when the menu is destroyed. --- .../Scripts/Adapters/UI/Menus/SaveMenu.cs | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/Assets/Gothic-Core/Scripts/Adapters/UI/Menus/SaveMenu.cs b/Assets/Gothic-Core/Scripts/Adapters/UI/Menus/SaveMenu.cs index f8c4339aa..87d9c558f 100644 --- a/Assets/Gothic-Core/Scripts/Adapters/UI/Menus/SaveMenu.cs +++ b/Assets/Gothic-Core/Scripts/Adapters/UI/Menus/SaveMenu.cs @@ -36,6 +36,8 @@ public class SaveMenu : AbstractMenu private TMP_Text Version; private readonly SaveGame[] _saves = new SaveGame[16]; + // One thumbnail per slot, rebuilt whenever the slots are read again (after every save). + private readonly Texture2D[] _thumbnails = new Texture2D[16]; [SerializeField] private bool _isSaving; private bool _isLoading => !_isSaving; @@ -152,8 +154,15 @@ protected override bool IsMenuItemActive(string menuItemName) return (MenuItemCache[menuItemName].item.Flags & MenuItemFlag.Disabled) == 0; } + private void OnDestroy() + { + ReleaseThumbnails(); + } + private void FillSaveGameEntries() { + ReleaseThumbnails(); + var saveGameListPath = _saveGameService.SavesFolderPath; if (!Directory.Exists(saveGameListPath)) return; @@ -226,8 +235,7 @@ public void OnLoadGameSlotPointerEnter(int id) return; } - Thumbnail.GetComponent().material.mainTexture - = _textureCacheService.TryGetTexture(save.Thumbnail, "savegame_" + save.Metadata.Title); + Thumbnail.GetComponent().material.mainTexture = GetThumbnail(id, save); Thumbnail.SetActive(true); World.text = save.Metadata.World; SavedAt.text = save.Metadata.SaveDate; @@ -237,6 +245,40 @@ public void OnLoadGameSlotPointerEnter(int id) // Version.text = save.Metadata.VersionAppName; } + /// + /// The slot's thumbnail from its THUMB.SAV. Not from TextureCacheService's shared cache: it was keyed by the + /// title, so a slot overwritten under the same name (or two slots with the same or an empty name) showed the + /// old picture until the game was restarted. + /// + private Texture2D GetThumbnail(int id, SaveGame save) + { + if (_thumbnails[id] != null) + return _thumbnails[id]; + + _thumbnails[id] = _textureCacheService.TryGetTexture(save.Thumbnail, $"savegame{id}_thumbnail", + useCache: false); + if (_thumbnails[id] == null) + Logger.LogWarning($"[SaveMenu] Save slot {id} has no thumbnail.", LogCat.Ui); + + return _thumbnails[id]; + } + + private void ReleaseThumbnails() + { + // The shown thumbnail is destroyed below - the next hover shows the new one. + if (Thumbnail != null) + Thumbnail.SetActive(false); + + for (var i = 0; i < _thumbnails.Length; i++) + { + if (_thumbnails[i] == null) + continue; + + Destroy(_thumbnails[i]); + _thumbnails[i] = null; + } + } + public void OnLoadGameSlotPointerExit() { Thumbnail.SetActive(false);