summaryrefslogtreecommitdiffstats
path: root/modules/mono/glue/base_object_glue.cpp
diff options
context:
space:
mode:
authorIgnacio Etcheverry <ignalfonsore@gmail.com>2018-12-01 02:23:55 +0100
committerIgnacio Etcheverry <ignalfonsore@gmail.com>2018-12-01 02:28:24 +0100
commitf6f2be7577f0f952c446064252339b7142109ea7 (patch)
tree3dfa908fbaf0a3a1b9a3b6be101dd6a77d8160c1 /modules/mono/glue/base_object_glue.cpp
parentb613c29053ef30a6be184aed6b9be5df46443db6 (diff)
downloadredot-engine-f6f2be7577f0f952c446064252339b7142109ea7.tar.gz
Fix crash due to ~CSharpInstance() being called on freed instance
This would be the case when calling SetScript on an object with a C# script.
Diffstat (limited to 'modules/mono/glue/base_object_glue.cpp')
-rw-r--r--modules/mono/glue/base_object_glue.cpp20
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;
}