Skip to content

Commit

Permalink
fix busylooping on failure in a CLR function
Browse files Browse the repository at this point in the history
  • Loading branch information
vddCore committed Nov 13, 2023
1 parent 2c24718 commit 8356eb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions FrontEnd/EVIL.evil/EvmFrontEnd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,25 @@ private void SetIncludePathsGlobal()

private void CrashHandler(Fiber fiber, Exception exception)
{
var callStack = fiber.CallStack;
var top = callStack.Peek().As<ScriptStackFrame>();
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<ScriptStackFrame>();
}
else
{
scriptTop = top.As<ScriptStackFrame>();
}

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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8356eb9

Please sign in to comment.