diff options
author | Ignacio Etcheverry <neikeq@users.noreply.github.com> | 2018-12-01 02:38:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-01 02:38:58 +0100 |
commit | ca28c455bfdc8408485c217c17f07011c0b43f64 (patch) | |
tree | 3dfa908fbaf0a3a1b9a3b6be101dd6a77d8160c1 /modules/mono/glue | |
parent | b613c29053ef30a6be184aed6b9be5df46443db6 (diff) | |
parent | f6f2be7577f0f952c446064252339b7142109ea7 (diff) |
Merge pull request #24098 from neikeq/kk
Fix crash due to ~CSharpInstance() being called on freed instance
Diffstat (limited to 'modules/mono/glue')
-rw-r--r-- | modules/mono/glue/base_object_glue.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/modules/mono/glue/base_object_glue.cpp b/modules/mono/glue/base_object_glue.cpp index d718c3cc61..58916c5283 100644 --- a/modules/mono/glue/base_object_glue.cpp +++ b/modules/mono/glue/base_object_glue.cpp @@ -54,8 +54,10 @@ void godot_icall_Object_Disposed(MonoObject *p_obj, Object *p_ptr) { if (p_ptr->get_script_instance()) { CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(p_ptr->get_script_instance()); if (cs_instance) { - cs_instance->mono_object_disposed(p_obj); - p_ptr->set_script_instance(NULL); + if (!cs_instance->is_destructing_script_instance()) { + cs_instance->mono_object_disposed(p_obj); + p_ptr->set_script_instance(NULL); + } return; } } @@ -82,12 +84,14 @@ void godot_icall_Reference_Disposed(MonoObject *p_obj, Object *p_ptr, bool p_is_ if (ref->get_script_instance()) { CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(ref->get_script_instance()); if (cs_instance) { - bool r_owner_deleted; - cs_instance->mono_object_disposed_baseref(p_obj, p_is_finalizer, r_owner_deleted); - if (!r_owner_deleted && !p_is_finalizer) { - // If the native instance is still alive and Dispose() was called - // (instead of the finalizer), then we remove the script instance. - ref->set_script_instance(NULL); + if (!cs_instance->is_destructing_script_instance()) { + bool r_owner_deleted; + cs_instance->mono_object_disposed_baseref(p_obj, p_is_finalizer, r_owner_deleted); + if (!r_owner_deleted && !p_is_finalizer) { + // If the native instance is still alive and Dispose() was called + // (instead of the finalizer), then we remove the script instance. + ref->set_script_instance(NULL); + } } return; } |