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!
This commit is contained in:
Aleos 2019-07-29 19:16:07 -04:00 committed by GitHub
parent 3dd388ac66
commit 8050f7c84e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;