From 7dc9bf3766637523ccff5ae7f4a408ebdfedeae5 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 23 Feb 2026 04:52:40 -0800 Subject: [PATCH] Fix M2 bone buffer leak on instance removal removeInstance() and removeInstances() were erasing M2Instances without calling destroyInstanceBones(), leaking VMA bone buffers permanently. This caused framerate to drop and never recover after NPC encounters. --- src/rendering/m2_renderer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/rendering/m2_renderer.cpp b/src/rendering/m2_renderer.cpp index 9644d187..0d28e9d2 100644 --- a/src/rendering/m2_renderer.cpp +++ b/src/rendering/m2_renderer.cpp @@ -3099,6 +3099,7 @@ void M2Renderer::setInstanceTransform(uint32_t instanceId, const glm::mat4& tran void M2Renderer::removeInstance(uint32_t instanceId) { for (auto it = instances.begin(); it != instances.end(); ++it) { if (it->id == instanceId) { + destroyInstanceBones(*it); instances.erase(it); rebuildSpatialIndex(); return; @@ -3113,6 +3114,11 @@ void M2Renderer::removeInstances(const std::vector& instanceIds) { std::unordered_set toRemove(instanceIds.begin(), instanceIds.end()); const size_t oldSize = instances.size(); + for (auto& inst : instances) { + if (toRemove.count(inst.id)) { + destroyInstanceBones(inst); + } + } instances.erase(std::remove_if(instances.begin(), instances.end(), [&toRemove](const M2Instance& inst) { return toRemove.find(inst.id) != toRemove.end();