From a43a43ed8efe54369292a5e502da377f2fc87095 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Tue, 17 Mar 2026 13:38:18 -0700 Subject: [PATCH] fix: evict oldest minimap tile textures when cache exceeds 128 entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevents unbounded GPU memory growth in long play sessions where the player visits many zones. Tiles are inserted into a FIFO deque; when the count of successfully-loaded tiles exceeds MAX_TILE_CACHE (128), the oldest entry is destroyed and removed from both the cache map and the deque. At 256×256×4 bytes per tile this caps minimap GPU usage at ~32 MB. --- include/rendering/minimap.hpp | 4 ++++ src/rendering/minimap.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/rendering/minimap.hpp b/include/rendering/minimap.hpp index ca7c5345..906f4666 100644 --- a/include/rendering/minimap.hpp +++ b/include/rendering/minimap.hpp @@ -7,6 +7,7 @@ #include #include #include +#include #include namespace wowee { @@ -73,7 +74,10 @@ private: bool trsParsed = false; // Tile texture cache: hash → VkTexture + // Evicted (FIFO) when the count of successfully-loaded tiles exceeds MAX_TILE_CACHE. + static constexpr size_t MAX_TILE_CACHE = 128; std::unordered_map> tileTextureCache; + std::deque tileInsertionOrder; // hashes of successfully loaded tiles, oldest first std::unique_ptr noDataTexture; // Composite render target (3x3 tiles = 768x768) diff --git a/src/rendering/minimap.cpp b/src/rendering/minimap.cpp index f47264d0..cce494d9 100644 --- a/src/rendering/minimap.cpp +++ b/src/rendering/minimap.cpp @@ -228,6 +228,7 @@ void Minimap::shutdown() { if (tex) tex->destroy(device, alloc); } tileTextureCache.clear(); + tileInsertionOrder.clear(); if (noDataTexture) { noDataTexture->destroy(device, alloc); noDataTexture.reset(); } if (compositeTarget) { compositeTarget->destroy(device, alloc); compositeTarget.reset(); } @@ -362,6 +363,15 @@ VkTexture* Minimap::getOrLoadTileTexture(int tileX, int tileY) { VkTexture* ptr = tex.get(); tileTextureCache[hash] = std::move(tex); + tileInsertionOrder.push_back(hash); + + // Evict oldest tiles when cache grows too large to bound GPU memory usage. + while (tileInsertionOrder.size() > MAX_TILE_CACHE) { + const std::string& oldest = tileInsertionOrder.front(); + tileTextureCache.erase(oldest); + tileInsertionOrder.pop_front(); + } + return ptr; }