summaryrefslogtreecommitdiffstats
path: root/modules/mono/csharp_script.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/csharp_script.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/csharp_script.cpp')
-rw-r--r--modules/mono/csharp_script.cpp9
1 files changed, 6 insertions, 3 deletions
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<MonoGCHandle> &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, Ref<Mon
uint32_t pinned_gchandle = MonoGCHandle::new_strong_handle_pinned(p_expected_obj); // We might lock after this, so pin it
- 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);
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);