forked from mirror/OpenTTD
Fix #14362, 4b677e8256
: Don't crash old scripts doing silly instantiation (#14394)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user