From 09acc6f421a10f1cbe5095af5afd9e62ccf634b4 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Thu, 1 Jan 2026 21:39:15 -0600 Subject: [PATCH] feat(model): partially implement CM2Shared dtor --- src/model/CM2Shared.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/model/CM2Shared.hpp | 2 ++ 2 files changed, 42 insertions(+) diff --git a/src/model/CM2Shared.cpp b/src/model/CM2Shared.cpp index 5a910e0..456c067 100644 --- a/src/model/CM2Shared.cpp +++ b/src/model/CM2Shared.cpp @@ -12,6 +12,12 @@ #include "util/SFile.hpp" #include +void CM2Shared::LoadCanceledCallback(CAsyncObject* object) { + AsyncFileReadDestroyObject(object); + + // TODO free buffer? +} + void CM2Shared::LoadFailedCallback(void* arg) { CM2Shared* shared = static_cast(arg); @@ -52,6 +58,40 @@ void CM2Shared::SkinProfileLoadedCallback(void* arg) { shared->asyncObject = nullptr; } +CM2Shared::~CM2Shared() { + // TODO this->CancelAllDeferredSequences(); + + bool cancelPending = false; + + if (this->asyncObject) { + if (!AsyncFileReadCancel(this->asyncObject, &CM2Shared::LoadCanceledCallback)) { + cancelPending = true; + } + } + + // TODO + + if (this->textures) { + for (int32_t i = 0; i < this->m_data->textures.Count(); i++) { + auto texture = this->textures[i]; + + if (texture) { + HandleClose(texture); + } + } + + STORM_FREE(this->textures); + } + + // TODO + + if (this->m_skinSections) { + STORM_FREE(this->m_skinSections); + } + + // TODO +} + void CM2Shared::AddRef() { // TODO free list management etc diff --git a/src/model/CM2Shared.hpp b/src/model/CM2Shared.hpp index da66753..d7880a3 100644 --- a/src/model/CM2Shared.hpp +++ b/src/model/CM2Shared.hpp @@ -21,6 +21,7 @@ class SFile; class CM2Shared { public: // Static functions + static void LoadCanceledCallback(CAsyncObject* object); static void LoadFailedCallback(void* param); static void LoadSucceededCallback(void* param); static void SkinProfileLoadedCallback(void* param); @@ -65,6 +66,7 @@ class CM2Shared { , m_flag20(0) , m_flag40(0) {}; + ~CM2Shared(); void AddRef(); int32_t CallbackWhenLoaded(CM2Model* model); CShaderEffect* CreateSimpleEffect(uint32_t textureCount, uint16_t shader, uint16_t textureCoordComboIndex);