From b960a1cdd542a170329854391dc58ce8510deef7 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 20 Mar 2026 08:52:57 -0700 Subject: [PATCH] fix: invalidate macro spell cache when spells are learned/removed The macro primary spell cache stored 0 (no spell found) when a macro referenced a spell the player hadn't learned yet. After learning the spell from a trainer or leveling up, the cache was never refreshed, so the macro button stayed broken. Now tracks the known spell count and clears the cache when it changes, ensuring newly learned spells are resolved on the next frame. --- include/ui/game_screen.hpp | 1 + src/ui/game_screen.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/include/ui/game_screen.hpp b/include/ui/game_screen.hpp index a4ca889b..cd200126 100644 --- a/include/ui/game_screen.hpp +++ b/include/ui/game_screen.hpp @@ -437,6 +437,7 @@ private: // Macro cooldown cache: maps macro ID → resolved primary spell ID (0 = no spell found) std::unordered_map macroPrimarySpellCache_; + size_t macroCacheSpellCount_ = 0; // invalidates cache when spell list changes uint32_t resolveMacroPrimarySpellId(uint32_t macroId, game::GameHandler& gameHandler); // Death Knight rune bar: client-predicted fill (0.0=depleted, 1.0=ready) for smooth animation diff --git a/src/ui/game_screen.cpp b/src/ui/game_screen.cpp index 7c4bd892..fafe0379 100644 --- a/src/ui/game_screen.cpp +++ b/src/ui/game_screen.cpp @@ -8643,6 +8643,12 @@ VkDescriptorSet GameScreen::getSpellIcon(uint32_t spellId, pipeline::AssetManage } uint32_t GameScreen::resolveMacroPrimarySpellId(uint32_t macroId, game::GameHandler& gameHandler) { + // Invalidate cache when spell list changes (learning/unlearning spells) + size_t curSpellCount = gameHandler.getKnownSpells().size(); + if (curSpellCount != macroCacheSpellCount_) { + macroPrimarySpellCache_.clear(); + macroCacheSpellCount_ = curSpellCount; + } auto cacheIt = macroPrimarySpellCache_.find(macroId); if (cacheIt != macroPrimarySpellCache_.end()) return cacheIt->second;