summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-01-10 17:03:47 +0100
committerGitHub <noreply@github.com>2022-01-10 17:03:47 +0100
commitb3d208385f1bb119a37c91182c440df8e20955d4 (patch)
tree4ff8a62e84e6703d140669991f721f52046f371d /modules
parenteea510fc3518da2778035a840349094f31b8c662 (diff)
parent511e699feeaeb5b7ce5882b62d424af614a157cf (diff)
Merge pull request #56409 from cdemirer/fix-unexpected-copying-when-parameter-is-typed
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript_vm.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp
index 014a2ad3b8..e0facaf61d 100644
--- a/modules/gdscript/gdscript_vm.cpp
+++ b/modules/gdscript/gdscript_vm.cpp
@@ -488,7 +488,12 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a
memnew_placement(&stack[i + 3], Variant(*p_args[i]));
continue;
}
-
+ // If types already match, don't call Variant::construct(). Constructors of some types
+ // (e.g. packed arrays) do copies, whereas they pass by reference when inside a Variant.
+ if (argument_types[i].is_type(*p_args[i], false)) {
+ memnew_placement(&stack[i + 3], Variant(*p_args[i]));
+ continue;
+ }
if (!argument_types[i].is_type(*p_args[i], true)) {
r_err.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_err.argument = i;