From 642c763612b8dd519e2ec93e8a068054a49d2517 Mon Sep 17 00:00:00 2001 From: fallenoak Date: Mon, 3 Nov 2025 19:17:38 -0600 Subject: [PATCH] fix(model): correct logic in CM2Model::AttachToParent --- src/model/CM2Model.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/model/CM2Model.cpp b/src/model/CM2Model.cpp index f24fb0f..c31c9de 100644 --- a/src/model/CM2Model.cpp +++ b/src/model/CM2Model.cpp @@ -693,15 +693,20 @@ void CM2Model::AttachToParent(CM2Model* parent, uint32_t id, const C3Vector* pos this->SetAnimating(0); - auto& attachmentIndicesById = this->m_shared->m_data->attachmentIndicesById; + // Look up parent attachment index by given ID uint16_t attachIndex = 0xFFFF; - if (parent->m_loaded && id < attachmentIndicesById.count) { - attachIndex = attachmentIndicesById[id]; - } - if (attachIndex == 0xFFFF && !a5) { - return; + if (parent->m_loaded) { + auto& parentAttachmentIndicesById = parent->m_shared->m_data->attachmentIndicesById; + + if (id < parentAttachmentIndicesById.Count()) { + attachIndex = parentAttachmentIndicesById[id]; + } + + if (attachIndex == 0xFFFF && !a5) { + return; + } } this->m_attachIndex = attachIndex;