Fix #14362, 4b677e8256: Don't crash old scripts doing silly instantiation (#14394)

This commit is contained in:
Loïc Guilloux
2025-07-17 13:30:33 +02:00
committed by GitHub
parent bccbd64037
commit 1b01a0636c
3 changed files with 28 additions and 0 deletions

View File

@@ -130,6 +130,13 @@ bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::span<const
ScriptLog::Info(fmt::format("Downgrading API to be compatible with version {}", this->api_version));
HSQUIRRELVM vm = this->engine->GetVM();
sq_pushroottable(vm);
sq_pushstring(vm, "CompatScriptRootTable");
sq_pushroottable(vm);
sq_newslot(vm, -3, SQFalse);
sq_pop(vm, 1);
/* Downgrade the API till we are the same version as the script. The last
* entry in the list is always the current version, so skip that one. */
for (auto it = std::rbegin(api_versions) + 1; it != std::rend(api_versions); ++it) {
@@ -138,6 +145,11 @@ bool ScriptInstance::LoadCompatibilityScripts(Subdirectory dir, std::span<const
if (*it == this->api_version) break;
}
sq_pushroottable(vm);
sq_pushstring(vm, "CompatScriptRootTable");
sq_deleteslot(vm, -2, SQFalse);
sq_pop(vm, 1);
return true;
}