Fix container object list not constructed when loading

This commit is contained in:
smallmodel 2025-02-03 21:27:44 +01:00
parent 5f0a0d0363
commit 330b45a1ed
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -1,6 +1,6 @@
/*
===========================================================================
Copyright (C) 2024 the OpenMoHAA team
Copyright (C) 2025 the OpenMoHAA team
This file is part of OpenMoHAA source code.
@ -153,7 +153,7 @@ public:
void ArchiveRaw(void *data, size_t size);
void ArchiveObject(Class *obj);
void ArchiveObject(SafePtrBase* obj); // Added in OPM
void ArchiveObject(SafePtrBase *obj); // Added in OPM
qboolean ObjectPositionExists(void *obj);
@ -167,23 +167,29 @@ public:
template<class Type>
inline void Container<Type>::Archive(Archiver& arc, void (*ArchiveFunc)(Archiver& arc, Type *obj))
{
int num;
int i;
Type *obj;
int num;
int i;
if (arc.Loading()) {
arc.ArchiveInteger(&num);
Resize(num);
} else {
num = numobjects;
arc.ArchiveInteger(&num);
}
for (i = 1; i <= num; i++) {
if (num > numobjects) {
numobjects = num;
}
ArchiveFunc(arc, &objlist[i - 1]);
for (i = 0; i < num; i++) {
obj = new (objlist + i) Type();
ArchiveFunc(arc, obj);
}
} else {
num = numobjects;
arc.ArchiveInteger(&num);
for (i = 0; i < num; i++) {
ArchiveFunc(arc, &objlist[i]);
}
}
}
@ -303,7 +309,7 @@ void con_set<key, value>::Archive(Archiver& arc)
defaultEntry = e;
} else {
#ifndef NDEBUG
# ifndef NDEBUG
int total;
total = 0;
@ -316,13 +322,13 @@ void con_set<key, value>::Archive(Archiver& arc)
}
// it must match the number of elements
assert(total == count);
#else
# else
for (i = 0; i < tableLength; i++) {
for (e = table[i]; e != NULL; e = e->next) {
e->Archive(arc);
}
}
#endif
# endif
}
}