Browse Source

Fix: unintended `index out of range exception` on other exception

Akeit0 10 months ago
parent
commit
005ff07031
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/Lua/Runtime/LuaVirtualMachine.cs

+ 4 - 2
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -932,16 +932,18 @@ public static partial class LuaVirtualMachine
         }
         catch (Exception e)
         {
-            context.PopOnTopCallStackFrames();
+            
             context.State.CloseUpValues(context.Thread, context.FrameBase);
             LuaValueArrayPool.Return1024(context.ResultsBuffer, true);
             if (e is not LuaRuntimeException)
             {
-                var newException = new LuaRuntimeException(GetTracebacks(ref context), e);
+                var newException = new LuaRuntimeException(context.State.GetTraceback(), e);
                 context = default;
+                context.PopOnTopCallStackFrames();
                 throw newException;
             }
 
+            context.PopOnTopCallStackFrames();
             throw;
         }
     }