diff --git a/src/d_main.cpp b/src/d_main.cpp index d4003fbd23..90efa16ab5 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -984,6 +984,7 @@ void D_ErrorCleanup () } if (gamestate == GS_INTERMISSION) gamestate = GS_DEMOSCREEN; insave = false; + ClearGlobalVMStack(); } //========================================================================== diff --git a/src/playsim/dthinker.cpp b/src/playsim/dthinker.cpp index 8ef9659e59..16b7f666fc 100644 --- a/src/playsim/dthinker.cpp +++ b/src/playsim/dthinker.cpp @@ -250,6 +250,7 @@ void FThinkerCollection::DestroyAllThinkers() GC::FullGC(); if (error) { + ClearGlobalVMStack(); I_Error("DestroyAllThinkers failed"); } } diff --git a/src/scripting/vm/vm.h b/src/scripting/vm/vm.h index 49bb51704a..db55dce43c 100644 --- a/src/scripting/vm/vm.h +++ b/src/scripting/vm/vm.h @@ -110,6 +110,8 @@ public: void ThrowAbortException(EVMAbortException reason, const char *moreinfo, ...); void ThrowAbortException(VMScriptFunction *sfunc, VMOP *line, EVMAbortException reason, const char *moreinfo, ...); +void ClearGlobalVMStack(); + struct VMReturn { void *Location; diff --git a/src/scripting/vm/vmframe.cpp b/src/scripting/vm/vmframe.cpp index f8916e94a8..7c2a63b1f7 100644 --- a/src/scripting/vm/vmframe.cpp +++ b/src/scripting/vm/vmframe.cpp @@ -715,6 +715,14 @@ void ThrowVMException(VMException *x) #endif +void ClearGlobalVMStack() +{ + while (GlobalVMStack.PopFrame() != nullptr) + { + } +} + + ADD_STAT(VM) { double added = 0;