From 40e188f6876e22ccee0a30057f8201c8f85cad72 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sun, 26 Sep 2021 00:02:51 +0800 Subject: [PATCH] Fix crash when creating thread --- core/core_bind.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/core_bind.cpp b/core/core_bind.cpp index 1f028702f64..540d061eb00 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -1768,6 +1768,12 @@ void Thread::_start_func(void *ud) { Ref *tud = (Ref *)ud; Ref 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