Only archive used variables on the local VM stack

This commit is contained in:
smallmodel 2023-11-28 19:14:09 +01:00
parent e59200a7de
commit 2ac2800ecb
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512

View file

@ -235,24 +235,27 @@ void ScriptVMStack::Archive(Archiver& arc)
{ {
unsigned int size; unsigned int size;
unsigned int offset; unsigned int offset;
unsigned int numVars;
unsigned int i; unsigned int i;
if (arc.Saving()) { if (arc.Saving()) {
size = stackBottom - localStack; size = stackBottom - localStack;
offset = pTop - localStack; offset = pTop - localStack;
numVars = offset + 1;
arc.ArchiveUnsigned(&size); arc.ArchiveUnsigned(&size);
arc.ArchiveUnsigned(&offset); arc.ArchiveUnsigned(&offset);
} else { } else {
arc.ArchiveUnsigned(&size); arc.ArchiveUnsigned(&size);
arc.ArchiveUnsigned(&offset); arc.ArchiveUnsigned(&offset);
numVars = offset + 1;
Allocate(size); Allocate(size);
pTop = localStack + offset; pTop = localStack + offset;
} }
if (localStack) { if (localStack) {
for (i = 0; i < size; i++) { for (i = 0; i < numVars; i++) {
localStack[i].ArchiveInternal(arc); localStack[i].ArchiveInternal(arc);
} }
} }