Browse Source

Merge pull request #101 from Akeit0/fix-error-message

Fix: unintended `index out of range exception` on other exception
Akeit0 8 months ago
parent
commit
9dc2d2c16b
1 changed files with 3 additions and 2 deletions
  1. 3 2
      src/Lua/Runtime/LuaVirtualMachine.cs

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

@@ -932,16 +932,17 @@ 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.PopOnTopCallStackFrames();
                 context = default;
                 throw newException;
             }
 
+            context.PopOnTopCallStackFrames();
             throw;
         }
     }