Skip to content

Commit

Permalink
Fixes #2470 by dropping priority after crash
Browse files Browse the repository at this point in the history
Unlike with programs, in the interpreter the program context
that "crashed" is being re-used when an exception is thrown.
That meant the execution priority needed a reset.
  • Loading branch information
Dunbaratu committed Mar 22, 2019
1 parent 6f0fc44 commit dccdee8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/kOS.Safe/Execution/CPU.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,12 @@ public void KOSFixedUpdate(double deltaTime)
// interpreter context
SkipCurrentInstructionId();
stack.Clear(); // Get rid of this interpreter command's cruft.

// If it threw exception during a trigger with higher priority (like lock steering) before
// reaching its OpcodeReturn, it's important to drop the interpreter context's priority
// back down so interrupts will work correctly again. Unlike with a *Program*, with the
// interpreter we're re-using the same programcontext after the crash:
CurrentPriority = InterruptPriority.Normal;
}
else
{
Expand Down Expand Up @@ -1367,7 +1373,7 @@ private void ProcessTriggers()
for (int index = 0 ; index < currentContext.ActiveTriggerCount() ; ++index)
{
TriggerInfo trigger = currentContext.GetTriggerByIndex(index);

// If the program is ended from within a trigger, the trigger list will be empty and the pointer
// will be invalid. Only execute the trigger if it still exists, AND if it's of a higher priority
// than the current CPU priority level. (If it's the same or less priority as the curent CPU priority,
Expand Down
2 changes: 1 addition & 1 deletion src/kOS.Safe/Execution/ProgramContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using kOS.Safe.Binding;
using kOS.Safe.Compilation;
Expand Down
5 changes: 3 additions & 2 deletions src/kOS.Safe/Execution/TriggerInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using kOS.Safe.Encapsulation;
using kOS.Safe.Execution;
Expand Down Expand Up @@ -202,6 +202,7 @@ public override int GetHashCode()

public override string ToString()
{
return string.Format("TriggerInfo: {0}:{1}:(arg count: {2})", EntryPoint, (IsCSharpCallback ? "callback" : "non-callback"), Args.Count);
return string.Format("TriggerInfo: {0}:{1}:(arg count: {2}):{3}",
EntryPoint, (IsCSharpCallback ? "callback" : "non-callback"), Args.Count, Priority);
}
}

0 comments on commit dccdee8

Please sign in to comment.