浏览代码

GDScript: for loop override stack variable bug fix

Fix: #42050
Thakee Nathees 5 年之前
父节点
当前提交
119936d939
共有 1 个文件被更改,包括 5 次插入3 次删除
  1. 5 3
      modules/gdscript/gdscript_byte_codegen.cpp

+ 5 - 3
modules/gdscript/gdscript_byte_codegen.cpp

@@ -579,8 +579,8 @@ void GDScriptByteCodeGenerator::write_endif() {
 }
 
 void GDScriptByteCodeGenerator::write_for(const Address &p_variable, const Address &p_list) {
-	int counter_pos = increase_stack() | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
-	int container_pos = increase_stack() | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
+	int counter_pos = add_temporary() | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
+	int container_pos = add_temporary() | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
 
 	current_breaks_to_patch.push_back(List<int>());
 
@@ -628,7 +628,9 @@ void GDScriptByteCodeGenerator::write_endfor() {
 	}
 	current_breaks_to_patch.pop_back();
 
-	current_stack_size -= 2; // Remove loop temporaries.
+	// Remove loop temporaries.
+	pop_temporary();
+	pop_temporary();
 }
 
 void GDScriptByteCodeGenerator::start_while_condition() {