Parcourir la source

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!
Aleos il y a 5 ans
Parent
commit
8050f7c84e
1 fichiers modifiés avec 9 ajouts et 12 suppressions
  1. 9 12
      src/map/script.cpp

+ 9 - 12
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;