From 8356eb9ebcddb75a988946d8b897ebd5c55e4802 Mon Sep 17 00:00:00 2001 From: vddCore Date: Mon, 13 Nov 2023 18:10:48 +0100 Subject: [PATCH] fix busylooping on failure in a CLR function --- FrontEnd/EVIL.evil/EvmFrontEnd.cs | 18 +++++++++++++++--- .../Extensions/FunctionArguments.Expect.cs | 4 ++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/FrontEnd/EVIL.evil/EvmFrontEnd.cs b/FrontEnd/EVIL.evil/EvmFrontEnd.cs index e06869f3..47bc9c2a 100644 --- a/FrontEnd/EVIL.evil/EvmFrontEnd.cs +++ b/FrontEnd/EVIL.evil/EvmFrontEnd.cs @@ -275,13 +275,25 @@ private void SetIncludePathsGlobal() private void CrashHandler(Fiber fiber, Exception exception) { - var callStack = fiber.CallStack; - var top = callStack.Peek().As(); var fiberArray = _vm.Scheduler.Fibers.ToArray(); var fiberIndex = Array.IndexOf(fiberArray, fiber); + + var callStack = fiber.CallStack; + var top = callStack.Peek(); + ScriptStackFrame? scriptTop = null; var sb = new StringBuilder(); - sb.AppendLine($"Runtime error in fiber {fiberIndex}, function {top.Chunk.Name} (def. in {top.Chunk.DebugDatabase.DefinedInFile}:{top.Chunk.DebugDatabase.DefinedOnLine}): {exception.Message}"); + + if (top is NativeStackFrame) + { + scriptTop = callStack[1].As(); + } + else + { + scriptTop = top.As(); + } + + sb.AppendLine($"Runtime error in fiber {fiberIndex}, function {scriptTop.Chunk.Name} (def. in {scriptTop.Chunk.DebugDatabase.DefinedInFile}:{scriptTop.Chunk.DebugDatabase.DefinedOnLine}): {exception.Message}"); sb.AppendLine(); sb.AppendLine("Stack trace:"); sb.Append(fiber.StackTrace(false)); diff --git a/VirtualMachine/Ceres.Runtime/Extensions/FunctionArguments.Expect.cs b/VirtualMachine/Ceres.Runtime/Extensions/FunctionArguments.Expect.cs index e6f3aeb6..ee1ab53b 100644 --- a/VirtualMachine/Ceres.Runtime/Extensions/FunctionArguments.Expect.cs +++ b/VirtualMachine/Ceres.Runtime/Extensions/FunctionArguments.Expect.cs @@ -17,9 +17,9 @@ public static DynamicValue[] ExpectTypeAt(this DynamicValue[] args, int index, D if (argType != type) { - if (argType == DynamicValueType.Nil) + if (allowNil) { - if (allowNil) + if (argType == DynamicValueType.Nil) { return args; }