From cc4ef3b898598ee6331b464bb8e208ea9bc93dd8 Mon Sep 17 00:00:00 2001 From: Lactozilla <jp6781615@gmail.com> Date: Mon, 29 Apr 2024 23:56:37 -0300 Subject: [PATCH] Add a branch limit Clarify why a script was terminated --- src/acs/environment.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/acs/environment.cpp b/src/acs/environment.cpp index fbec87cc29..5147bbb154 100644 --- a/src/acs/environment.cpp +++ b/src/acs/environment.cpp @@ -48,6 +48,9 @@ Environment::Environment() // Not that we're adding any modules to it, though. :p global->active = true; + // Set the branch limit (same as in ZDoom) + branchLimit = 2000000; + // Add the data & function pointers. // Starting with raw ACS0 codes. I'm using this classic-style @@ -441,5 +444,39 @@ ACSVM::Word Environment::callSpecImpl void Environment::printKill(ACSVM::Thread *thread, ACSVM::Word type, ACSVM::Word data) { - CONS_Alert(CONS_ERROR, "ACSVM ERROR: Kill %u:%d at %lu\n", type, data, (thread->codePtr - thread->module->codeV.data() - 1)); + std::string scriptName; + + ACSVM::String *scriptNamePtr = (thread->script != nullptr) ? (thread->script->name.s) : nullptr; + if (scriptNamePtr && scriptNamePtr->len) + scriptName = std::string(scriptNamePtr->str); + else + scriptName = std::to_string((int)thread->script->name.i); + + ACSVM::KillType killType = static_cast<ACSVM::KillType>(type); + + if (killType == ACSVM::KillType::BranchLimit) + { + CONS_Alert(CONS_ERROR, "Terminated runaway script %s\n", scriptName.c_str()); + return; + } + else if (killType == ACSVM::KillType::UnknownCode) + { + CONS_Alert(CONS_ERROR, "ACSVM ERROR: Unknown opcode %d in script %s\n", data, scriptName.c_str()); + } + else if (killType == ACSVM::KillType::UnknownFunc) + { + CONS_Alert(CONS_ERROR, "ACSVM ERROR: Unknown function %d in script %s\n", data, scriptName.c_str()); + } + else if (killType == ACSVM::KillType::OutOfBounds) + { + CONS_Alert(CONS_ERROR, "ACSVM ERROR: Jumped to out of bounds location %lu in script %s\n", + (thread->codePtr - thread->module->codeV.data() - 1), scriptName.c_str()); + } + else + { + CONS_Alert(CONS_ERROR, "ACSVM ERROR: Kill %u:%d at %lu in script %s\n", + type, data, (thread->codePtr - thread->module->codeV.data() - 1), scriptName.c_str()); + } + + CONS_Printf("Script terminated.\n"); } -- GitLab