diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-19 21:18:18 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-06-19 21:18:18 +0200 |
| commit | ae00187b58cc5ec20ceb2c00c912820c756ed275 (patch) | |
| tree | ea7afe68cf0826268484d2d8f1d5029ec6e049d4 /modules/gdscript/gdscript_vm.cpp | |
| parent | 5f9175f969807410bc077fc9caa0fa53febd4319 (diff) | |
| parent | aebbbda08060e0cd130c5a682cd91b6babb18c67 (diff) | |
| download | redot-engine-ae00187b58cc5ec20ceb2c00c912820c756ed275.tar.gz | |
Merge pull request #77129 from dalexeev/gds-fix-static-var-bugs-part-1
GDScript: Fix some bugs with static variables and functions
Diffstat (limited to 'modules/gdscript/gdscript_vm.cpp')
| -rw-r--r-- | modules/gdscript/gdscript_vm.cpp | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 0ffc025c24..4545689bd9 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -217,6 +217,8 @@ void (*type_init_function_table[])(Variant *) = { &&OPCODE_GET_NAMED_VALIDATED, \ &&OPCODE_SET_MEMBER, \ &&OPCODE_GET_MEMBER, \ + &&OPCODE_SET_STATIC_VARIABLE, \ + &&OPCODE_GET_STATIC_VARIABLE, \ &&OPCODE_ASSIGN, \ &&OPCODE_ASSIGN_TRUE, \ &&OPCODE_ASSIGN_FALSE, \ @@ -666,7 +668,6 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a Variant *m_v = instruction_args[m_idx] #ifdef DEBUG_ENABLED - uint64_t function_start_time = 0; uint64_t function_call_time = 0; @@ -679,11 +680,12 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a bool exit_ok = false; bool awaited = false; #endif + #ifdef DEBUG_ENABLED - int variant_address_limits[ADDR_TYPE_MAX] = { _stack_size, _constant_count, p_instance ? p_instance->members.size() : 0, script->static_variables.size() }; + int variant_address_limits[ADDR_TYPE_MAX] = { _stack_size, _constant_count, p_instance ? p_instance->members.size() : 0 }; #endif - Variant *variant_addresses[ADDR_TYPE_MAX] = { stack, _constants_ptr, p_instance ? p_instance->members.ptrw() : nullptr, script->static_variables.ptrw() }; + Variant *variant_addresses[ADDR_TYPE_MAX] = { stack, _constants_ptr, p_instance ? p_instance->members.ptrw() : nullptr }; #ifdef DEBUG_ENABLED OPCODE_WHILE(ip < _code_size) { @@ -1171,6 +1173,42 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a } DISPATCH_OPCODE; + OPCODE(OPCODE_SET_STATIC_VARIABLE) { + CHECK_SPACE(4); + + GET_VARIANT_PTR(value, 0); + + GET_VARIANT_PTR(_class, 1); + GDScript *gdscript = Object::cast_to<GDScript>(_class->operator Object *()); + GD_ERR_BREAK(!gdscript); + + int index = _code_ptr[ip + 3]; + GD_ERR_BREAK(index < 0 || index >= gdscript->static_variables.size()); + + gdscript->static_variables.write[index] = *value; + + ip += 4; + } + DISPATCH_OPCODE; + + OPCODE(OPCODE_GET_STATIC_VARIABLE) { + CHECK_SPACE(4); + + GET_VARIANT_PTR(target, 0); + + GET_VARIANT_PTR(_class, 1); + GDScript *gdscript = Object::cast_to<GDScript>(_class->operator Object *()); + GD_ERR_BREAK(!gdscript); + + int index = _code_ptr[ip + 3]; + GD_ERR_BREAK(index < 0 || index >= gdscript->static_variables.size()); + + *target = gdscript->static_variables[index]; + + ip += 4; + } + DISPATCH_OPCODE; + OPCODE(OPCODE_ASSIGN) { CHECK_SPACE(3); GET_VARIANT_PTR(dst, 0); @@ -3620,7 +3658,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #endif // Free stack, except reserved addresses. - for (int i = 3; i < _stack_size; i++) { + for (int i = FIXED_ADDRESSES_MAX; i < _stack_size; i++) { stack[i].~Variant(); } #ifdef DEBUG_ENABLED @@ -3628,7 +3666,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a #endif // Always free reserved addresses, since they are never copied. - for (int i = 0; i < 3; i++) { + for (int i = 0; i < FIXED_ADDRESSES_MAX; i++) { stack[i].~Variant(); } |
