From b4455ffd75e48fddcc072e00ef8a6cccb664e30d Mon Sep 17 00:00:00 2001 From: "Matthew A. Robinson" Date: Mon, 22 Mar 2021 11:38:26 -0400 Subject: [PATCH] Add mutex protecting script bindings map from getting corrupted --- modules/mono/mono_gd/gd_mono_internals.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp index d6fac4ca130..32c2182bf9c 100644 --- a/modules/mono/mono_gd/gd_mono_internals.cpp +++ b/modules/mono/mono_gd/gd_mono_internals.cpp @@ -90,7 +90,11 @@ void tie_managed_to_unmanaged(MonoObject *managed, Object *unmanaged) { // The object was just created, no script instance binding should have been attached CRASH_COND(unmanaged->has_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index())); - void *data = (void *)CSharpLanguage::get_singleton()->insert_script_binding(unmanaged, script_binding); + void *data; + { + MutexLock lock(CSharpLanguage::get_singleton()->get_language_bind_mutex()); + data = (void *)CSharpLanguage::get_singleton()->insert_script_binding(unmanaged, script_binding); + } // Should be thread safe because the object was just created and nothing else should be referencing it unmanaged->set_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index(), data);