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.
This commit is contained in:
Kelsi 2026-02-23 04:52:40 -08:00
parent 2124761ea8
commit 7dc9bf3766

View file

@ -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<uint32_t>& instanceIds) {
std::unordered_set<uint32_t> 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();