From 4190cb796f588e7117dfba8b4d2fd662d29810ea 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(); }