From f6f2be7577f0f952c446064252339b7142109ea7 Mon Sep 17 00:00:00 2001 From: Ignacio Etcheverry Date: Sat, 1 Dec 2018 02:23:55 +0100 Subject: 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. --- modules/mono/csharp_script.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'modules/mono/csharp_script.cpp') diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index e3df0246ab..3c818898e6 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -993,7 +993,7 @@ void CSharpLanguage::set_language_index(int p_idx) { void CSharpLanguage::release_script_gchandle(Ref &p_gchandle) { - if (!p_gchandle->is_released()) { // Do not locking unnecessarily + if (!p_gchandle->is_released()) { // Do not lock unnecessarily SCOPED_MUTEX_LOCK(get_singleton()->script_gchandle_release_mutex); p_gchandle->release(); } @@ -1003,7 +1003,7 @@ void CSharpLanguage::release_script_gchandle(MonoObject *p_expected_obj, Refis_released()) { // Do not locking unnecessarily + if (!p_gchandle->is_released()) { // Do not lock unnecessarily SCOPED_MUTEX_LOCK(get_singleton()->script_gchandle_release_mutex); MonoObject *target = p_gchandle->get_target(); @@ -1754,7 +1754,8 @@ CSharpInstance::CSharpInstance() : base_ref(false), ref_dying(false), unsafe_referenced(false), - predelete_notified(false) { + predelete_notified(false), + destructing_script_instance(false) { } CSharpInstance::~CSharpInstance() { @@ -1771,7 +1772,9 @@ CSharpInstance::~CSharpInstance() { if (mono_object) { MonoException *exc = NULL; + destructing_script_instance = true; GDMonoUtils::dispose(mono_object, &exc); + destructing_script_instance = false; if (exc) { GDMonoUtils::set_pending_exception(exc); -- cgit v1.2.3