From e0f8efcb016390b736dbdadac171b866472b8c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Sat, 31 Jul 2021 09:36:34 +0200 Subject: [PATCH] Fix thread start with no user data when target has no default argument (cherry picked from commit 7ca805164532f6fc0e488c6cef1e328fa95fb95b) --- core/bind/core_bind.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp index 53b704edba6..0f36cdb61d5 100644 --- a/core/bind/core_bind.cpp +++ b/core/bind/core_bind.cpp @@ -2589,7 +2589,36 @@ void _Thread::_start_func(void *ud) { memdelete(tud); Variant::CallError ce; const Variant *arg[1] = { &t->userdata }; - int argc = (int)(arg[0]->get_type() != Variant::NIL); + int argc = 0; + if (arg[0]->get_type() != Variant::NIL) { + // Just pass to the target function whatever came as user data + argc = 1; + } else { + // There are two cases of null user data: + // a) The target function has zero parameters and the caller is just honoring that. + // b) The target function has at least one parameter with no default and the caller is + // leveraging the fact that user data defaults to null in Thread.start(). + // We care about the case of more than one parameter because, even if a thread + // function can have one at most, out mindset here is to do our best with the + // only/first one and let the call handle any other error conditions, like too + // much arguments. + // We must check if we are in case b). + int target_param_count = 0; + int target_default_arg_count = 0; + Ref