From 712d800491566c880b6b565dfb40d36fbefc2365 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 31 Jan 2022 23:32:38 +0900 Subject: [PATCH] [gamecode] Save return ptr for chained calls It turns out the return pointer still needs to be saved even when a builtin sets up a chain call to progs, but rather than the pointer being simply restored, it needs to be saved in the call stack exactly as if the function was called directly by progs. This fixes the invalid self issue quite thoroughly: parameter state seems to be correct across all calls now. I should set up an automated test now that I know and understand the situation. --- libs/gamecode/pr_exec.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/gamecode/pr_exec.c b/libs/gamecode/pr_exec.c index cd493bea8..200e0c0d8 100644 --- a/libs/gamecode/pr_exec.c +++ b/libs/gamecode/pr_exec.c @@ -457,6 +457,8 @@ PR_CallFunction (progs_t *pr, pr_func_t fnum, pr_type_t *return_ptr) f->func (pr); if (builtin_depth == pr->pr_depth) { pr->pr_return = saved_return; + } else if (builtin_depth < pr->pr_depth) { + pr->pr_stack[builtin_depth].return_ptr = saved_return; } return 0; } else {