From 8050f7c84ed277b98377b54cadb5d2d0ceeb8f05 Mon Sep 17 00:00:00 2001 From: Aleos Date: Mon, 29 Jul 2019 19:16:07 -0400 Subject: [PATCH] Properly free function script counter (#4269) * Fixes #3613. * Script functions will now properly reset the script instance counter when the function terminates the script. Thanks to @Tokeiburu! --- src/map/script.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/map/script.cpp b/src/map/script.cpp index 604274ecde..913e6b19c5 100644 --- a/src/map/script.cpp +++ b/src/map/script.cpp @@ -4410,6 +4410,15 @@ void run_script_main(struct script_state *st) st->bk_st = NULL; } } else { + if (st->stack && st->stack->defsp >= 1 && st->stack->stack_data[st->stack->defsp - 1].type == C_RETINFO) { + for (int i = 0; i < st->stack->sp; i++) { + if (st->stack->stack_data[i].type == C_RETINFO) { // Grab the first, aka the original + st->script = st->stack->stack_data[i].u.ri->script; + break; + } + } + } + //Dispose of script. if ((sd = map_id2sd(st->rid))!=NULL) { //Restore previous stack and save char. @@ -9699,18 +9708,6 @@ BUILDIN_FUNC(end) st->state = END; - if (st->stack->defsp >= 1 && st->stack->stack_data[st->stack->defsp-1].type == C_RETINFO) { - int i; - - for(i = 0; i < st->stack->sp; i++) { - if (st->stack->stack_data[i].type == C_RETINFO) { // Grab the first, aka the original - struct script_retinfo *ri = st->stack->stack_data[i].u.ri; - st->script = ri->script; - break; - } - } - } - if( st->mes_active ) st->mes_active = 0;