From de3215afc98ed6f860992e868e2e90548efddf09 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Wed, 29 Oct 2025 14:53:12 -0500 Subject: [PATCH] feat(model): implement more of CM2Model dtor --- src/model/CM2Model.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++ src/model/CM2Model.hpp | 6 +++- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/model/CM2Model.cpp b/src/model/CM2Model.cpp index c863d1d..75dfaed 100644 --- a/src/model/CM2Model.cpp +++ b/src/model/CM2Model.cpp @@ -94,6 +94,15 @@ CM2Model::~CM2Model() { this->DetachFromScene(); + if (this->m_shared) { + // TODO + + this->FreeInternalResources(); + + this->m_shared->Release(); + this->m_shared = nullptr; + } + // TODO this->UnlinkFromAttachList(); @@ -955,6 +964,65 @@ LABEL_36: } } +void CM2Model::FreeInternalResources() { + if (!this->m_internalResources) { + return; + } + + if (this->m_bones) { + this->m_bones = nullptr; + } + + if (this->m_loops) { + this->m_loops = nullptr; + } + + if (this->m_skinSections) { + this->m_skinSections = nullptr; + } + + if (this->m_colors) { + this->m_colors = nullptr; + } + + if (this->m_textureWeights) { + this->m_textureWeights = nullptr; + } + + // TODO + // if (this->m_textureTransforms) { + // this->m_textureTransforms = nullptr; + // } + + if (this->m_attachments) { + this->m_attachments = nullptr; + } + + if (this->m_lights) { + for (int32_t i = 0; i < this->m_shared->m_data->lights.Count(); i++) { + this->m_lights[i].light.~CM2Light(); + } + + this->m_lights = nullptr; + } + + if (this->m_cameras) { + this->m_cameras = nullptr; + } + + // TODO + // if (this->m_ribbons) { + // this->m_ribbons = nullptr; + // } + + // TODO + // if (this->m_particles) { + // this->m_particles = nullptr; + // } + + STORM_FREE(this->m_internalResources); +} + C44Matrix CM2Model::GetAttachmentWorldTransform(uint32_t id) { if (!this->m_loaded) { this->WaitForLoad("GetAttachmentWorldTransform"); diff --git a/src/model/CM2Model.hpp b/src/model/CM2Model.hpp index 792ce93..2016847 100644 --- a/src/model/CM2Model.hpp +++ b/src/model/CM2Model.hpp @@ -96,7 +96,10 @@ class CM2Model { uint32_t uint74 = 0; float float88 = 0.0f; uint32_t uint90 = 0; - M2ModelBone* m_bones = nullptr; + union { + M2ModelBone* m_bones = nullptr; + void* m_internalResources; + }; C44Matrix* m_boneMatrices = nullptr; M2ModelColor* m_colors = nullptr; uint32_t* m_skinSections = nullptr; @@ -159,6 +162,7 @@ class CM2Model { void DetachFromParent(); void DetachFromScene(); void FindKey(M2ModelBoneSeq* sequence, const M2TrackBase& track, uint32_t& currentKey, uint32_t& nextKey, float& ratio); + void FreeInternalResources(); C44Matrix GetAttachmentWorldTransform(uint32_t id); CAaBox& GetBoundingBox(CAaBox& bounds); HCAMERA GetCameraByIndex(uint32_t index);