finish PreDelete and CheckPreDeletion. now there is no problem when deleting object

This commit is contained in:
2023-09-20 15:25:43 +08:00
parent a06f6a58c9
commit 81872053f0
16 changed files with 100 additions and 28 deletions

View File

@ -12,9 +12,27 @@ namespace LibCmo::CK2::ObjImpls {
m_GroupIndex(m_Context->GetObjectManager()->AllocateGroupGlobalIndex()) {}
CKGroup::~CKGroup() {
// free self allocated id
m_Context->GetObjectManager()->FreeGroupGlobalIndex(m_GroupIndex);
}
void CKGroup::PreDelete() {
CKBeObject::PreDelete();
// unlink all grouped object
for (auto& ptr : m_ObjectArray) {
static_cast<CKBeObject*>(ptr)->ExplicitSetGroup(m_GroupIndex, false);
}
m_ObjectArray.clear();
}
void CKGroup::CheckPreDeletion() {
CKBeObject::CheckPreDeletion();
// remove self invalid object ptr
XContainer::NSXObjectPointerArray::PreDeletedCheck(m_ObjectArray, m_Context);
}
bool CKGroup::Save(CKStateChunk* chunk, CKFileVisitor* file, CKDWORD flags) {
bool suc = CKBeObject::Save(chunk, file, flags);
if (!suc) return false;