summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/gdscript_byte_codegen.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2021-05-17 17:34:19 +0200
committerGitHub <noreply@github.com>2021-05-17 17:34:19 +0200
commit2fcfc83da91ca6c2e4670d3cdf01ee27d65f667b (patch)
tree423898b2c0c335c37fb64ddcc9af474d321cefc9 /modules/gdscript/gdscript_byte_codegen.cpp
parentfead3fff178274c760cfb481dc2f51a44a4aa069 (diff)
parent10a1f649680971c63b110d33cffd9aa5b1aaf6a9 (diff)
downloadredot-engine-2fcfc83da91ca6c2e4670d3cdf01ee27d65f667b.tar.gz
Merge pull request #48793 from vnen/gdscript-fix-temp-type-adjust
GDScript: Fix crash caused by uninitialized temp stack slots
Diffstat (limited to 'modules/gdscript/gdscript_byte_codegen.cpp')
-rw-r--r--modules/gdscript/gdscript_byte_codegen.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp
index e3e88e5ed1..ea34a2ca2d 100644
--- a/modules/gdscript/gdscript_byte_codegen.cpp
+++ b/modules/gdscript/gdscript_byte_codegen.cpp
@@ -129,12 +129,6 @@ uint32_t GDScriptByteCodeGenerator::add_temporary(const GDScriptDataType &p_type
int idx = temporaries.size();
pool.push_back(idx);
temporaries.push_back(new_temp);
-
- // First time using this, so adjust to the proper type.
- if (temp_type != Variant::NIL) {
- Address addr(Address::TEMPORARY, idx, p_type);
- write_type_adjust(addr, temp_type);
- }
}
int slot = pool.front()->get();
pool.pop_front();
@@ -189,8 +183,12 @@ GDScriptFunction *GDScriptByteCodeGenerator::write_end() {
append(GDScriptFunction::OPCODE_END, 0);
for (int i = 0; i < temporaries.size(); i++) {
+ int stack_index = i + max_locals + RESERVED_STACK;
for (int j = 0; j < temporaries[i].bytecode_indices.size(); j++) {
- opcodes.write[temporaries[i].bytecode_indices[j]] = (i + max_locals + RESERVED_STACK) | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
+ opcodes.write[temporaries[i].bytecode_indices[j]] = stack_index | (GDScriptFunction::ADDR_TYPE_STACK << GDScriptFunction::ADDR_BITS);
+ }
+ if (temporaries[i].type != Variant::NIL) {
+ function->temporary_slots[stack_index] = temporaries[i].type;
}
}