From 08189df5287e36e7d3d8963a5b7e46929bd3f2ac Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 16 Feb 2026 00:19:07 -0800 Subject: [PATCH] Fix composite cache clearing to not delete NPC textures clearCompositeCache() now only clears the lookup map without deleting GPU textures, preventing NPC and other instance textures from being accidentally destroyed during player equipment changes. --- src/rendering/character_renderer.cpp | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/rendering/character_renderer.cpp b/src/rendering/character_renderer.cpp index 78a1ff00..8ca8eccf 100644 --- a/src/rendering/character_renderer.cpp +++ b/src/rendering/character_renderer.cpp @@ -576,22 +576,9 @@ GLuint CharacterRenderer::compositeTextures(const std::vector& laye } void CharacterRenderer::clearCompositeCache() { - // Delete GPU textures that aren't referenced by any model's texture slots - for (auto& [key, texId] : compositeCache_) { - if (texId && texId != whiteTexture) { - // Check if any model still references this texture - bool inUse = false; - for (const auto& [mid, gm] : models) { - for (GLuint tid : gm.textureIds) { - if (tid == texId) { inUse = true; break; } - } - if (inUse) break; - } - if (!inUse) { - glDeleteTextures(1, &texId); - } - } - } + // Just clear the lookup map so next compositeWithRegions() creates fresh textures. + // Don't delete GPU textures — they may still be referenced by models or instances. + // Orphaned textures will be cleaned up when their model/instance is destroyed. compositeCache_.clear(); }