1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Merge pull request #47295 from omegachysis/script-bind-mutex

Fix race condition on `script_binding` in C#
This commit is contained in:
Ignacio Roldán Etcheverry
2021-08-24 06:09:43 +02:00
committed by GitHub

View File

@@ -91,7 +91,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(CSharpLanguage::has_instance_binding(unmanaged));
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
CSharpLanguage::set_instance_binding(unmanaged, data);