aboutsummaryrefslogtreecommitdiff
path: root/core/bind/core_bind.cpp
diff options
context:
space:
mode:
authorJuan Linietsky2015-05-18 12:45:53 -0300
committerJuan Linietsky2015-05-18 12:45:53 -0300
commitf220183e40cb100cdfb8158c5217076377a62980 (patch)
treedcb151e1ffea54f8572a007bb4ec73a1bd0f627c /core/bind/core_bind.cpp
parent5900e7f589d50268d49e2e67d3a498d1b01fe03a (diff)
downloadgodot-f220183e40cb100cdfb8158c5217076377a62980.tar.gz
godot-f220183e40cb100cdfb8158c5217076377a62980.tar.zst
godot-f220183e40cb100cdfb8158c5217076377a62980.zip
fix a crash situation when starting a thread and other small fixes
Diffstat (limited to 'core/bind/core_bind.cpp')
-rw-r--r--core/bind/core_bind.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 06b71f05c..be3ce4f44 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -1757,7 +1757,9 @@ _Mutex::~_Mutex(){
void _Thread::_start_func(void *ud) {
- _Thread *t=(_Thread*)ud;
+ Ref<_Thread>* tud=(Ref<_Thread>*)ud;
+ Ref<_Thread> t=*tud;
+ memdelete(tud);
Variant::CallError ce;
const Variant* arg[1]={&t->userdata};
t->ret=t->target_instance->call(t->target_method,arg,1,ce);
@@ -1804,9 +1806,11 @@ Error _Thread::start(Object *p_instance,const StringName& p_method,const Variant
userdata=p_userdata;
active=true;
+ Ref<_Thread> *ud = memnew( Ref<_Thread>(this) );
+
Thread::Settings s;
s.priority=(Thread::Priority)p_priority;
- thread = Thread::create(_start_func,this,s);
+ thread = Thread::create(_start_func,ud,s);
if (!thread) {
active=false;
target_method=StringName();
@@ -1867,5 +1871,8 @@ _Thread::_Thread() {
_Thread::~_Thread() {
+ if (active) {
+ ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running..")
+ }
ERR_FAIL_COND(active==true);
}