Skip to content

Commit

Permalink
Fix rerun bug
Browse files Browse the repository at this point in the history
First found when using rye-ebitengine.

Under certain circumstances, this happens when a Rye program calls a native binding, which internally calls a Rye function as a callback.

I'm still not 100% sure how the bug came to be, but here's my theory: Calls to CallFunctionArgsN are nested, meaning we need to build something like a "call stack" to keep track of the "program counter" (here ps.Ser.pos). It is the job of psX to act as the "inner stack frame". Previously, ps was used, which would just override the "outer stack frame's" program counter, causing it to set to position 0, i.e. re-running the program from the start.
  • Loading branch information
xypwn committed Sep 7, 2024
1 parent 21f1c1c commit 65e7c3f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions evaldo/evaldo.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ func CallFunctionArgs2(fn env.Function, ps *env.ProgramState, arg0 env.Object, a
/// ps.Ctx = fnCtx

var result *env.ProgramState
ps.Ser.SetPos(0)
psX.Ser.SetPos(0)
result = EvalBlockInj(psX, arg0, true)
// fmt.Println(result)
// fmt.Println(result.Res)
Expand Down Expand Up @@ -818,7 +818,7 @@ func CallFunctionArgs4(fn env.Function, ps *env.ProgramState, arg0 env.Object, a

// END TRY
var result *env.ProgramState
ps.Ser.SetPos(0)
psX.Ser.SetPos(0)
result = EvalBlockInj(psX, arg0, true)
MaybeDisplayFailureOrError(result, result.Idx)
if result.ForcedResult != nil {
Expand Down Expand Up @@ -878,7 +878,7 @@ func CallFunctionArgsN(fn env.Function, ps *env.ProgramState, ctx *env.RyeCtx, a

// END TRY
var result *env.ProgramState
ps.Ser.SetPos(0)
psX.Ser.SetPos(0)
if len(args) > 0 {
result = EvalBlockInj(psX, args[0], true)
} else {
Expand Down

0 comments on commit 65e7c3f

Please sign in to comment.