diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2021-09-26 00:02:51 +0800 |
---|---|---|
committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2021-09-29 22:08:12 +0800 |
commit | 40e188f6876e22ccee0a30057f8201c8f85cad72 (patch) | |
tree | c1a18dea4b8409990b93d111231ce4f8304d6728 /core | |
parent | 3db672c89ebc5b75633a144360dc95e794647e8a (diff) |
Fix crash when creating thread
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 1f028702f6..540d061eb0 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1768,6 +1768,12 @@ void Thread::_start_func(void *ud) { Ref<Thread> *tud = (Ref<Thread> *)ud; Ref<Thread> t = *tud; memdelete(tud); + + Object *target_instance = t->target_callable.get_object(); + if (!target_instance) { + ERR_FAIL_MSG(vformat("Could not call function '%s' on previously freed instance to start thread %s.", t->target_callable.get_method(), t->get_id())); + } + Callable::CallError ce; const Variant *arg[1] = { &t->userdata }; int argc = 0; @@ -1786,15 +1792,17 @@ void Thread::_start_func(void *ud) { // We must check if we are in case b). int target_param_count = 0; int target_default_arg_count = 0; - Ref<Script> script = t->target_callable.get_object()->get_script(); + Ref<Script> script = target_instance->get_script(); if (script.is_valid()) { MethodInfo mi = script->get_method_info(t->target_callable.get_method()); target_param_count = mi.arguments.size(); target_default_arg_count = mi.default_arguments.size(); } else { - MethodBind *method = ClassDB::get_method(t->target_callable.get_object()->get_class_name(), t->target_callable.get_method()); - target_param_count = method->get_argument_count(); - target_default_arg_count = method->get_default_argument_count(); + MethodBind *method = ClassDB::get_method(target_instance->get_class_name(), t->target_callable.get_method()); + if (method) { + target_param_count = method->get_argument_count(); + target_default_arg_count = method->get_default_argument_count(); + } } if (target_param_count >= 1 && target_default_arg_count < target_param_count) { argc = 1; |