From 85d2a23a62657c4e8b015646602ababf0b6f39d3 Mon Sep 17 00:00:00 2001 From: "Preslav.Laptop" Date: Thu, 28 Nov 2024 15:00:58 +0000 Subject: [PATCH] Move the script reload function to outside the lock to prevent worker threads from the ResourceLoader::load method from causing a deadlock --- .../GodotSharp/Core/Bridge/ScriptManagerBridge.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs index a327b9cd35..0ed36d43ed 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Bridge/ScriptManagerBridge.cs @@ -493,6 +493,8 @@ namespace Godot.Bridge { _scriptTypeBiMap.ReadWriteLock.ExitUpgradeableReadLock(); } + + NativeFuncs.godotsharp_internal_reload_registered_script(outScript->Reference); } internal static unsafe void GetOrLoadOrCreateScriptForType(Type scriptType, godot_ref* outScript) @@ -527,12 +529,14 @@ namespace Godot.Bridge CreateScriptBridgeForType(scriptType, outScript); scriptPath = null; - return false; } finally { _scriptTypeBiMap.ReadWriteLock.ExitUpgradeableReadLock(); } + + NativeFuncs.godotsharp_internal_reload_registered_script(outScript->Reference); + return false; } static string GetVirtualConstructedGenericTypeScriptPath(Type scriptType, string scriptPath) @@ -597,6 +601,9 @@ namespace Godot.Bridge } } + /// + /// WARNING: We need to make sure that after unlocking the bimap, we call godotsharp_internal_reload_registered_script + /// private static unsafe void CreateScriptBridgeForType(Type scriptType, godot_ref* outScript) { Debug.Assert(!scriptType.IsGenericTypeDefinition, $"Script type must be a constructed generic type or not generic at all. Type: {scriptType}."); @@ -613,8 +620,6 @@ namespace Godot.Bridge { _scriptTypeBiMap.ReadWriteLock.ExitWriteLock(); } - - NativeFuncs.godotsharp_internal_reload_registered_script(outScript->Reference); } [UnmanagedCallersOnly]