Move the script reload function to outside the

lock to prevent worker threads from the
ResourceLoader::load method from causing a
deadlock
This commit is contained in:
Preslav.Laptop
2024-11-28 15:00:58 +00:00
committed by Raul Santos
parent efb40c1524
commit 85d2a23a62

View File

@ -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
}
}
/// <summary>
/// WARNING: We need to make sure that after unlocking the bimap, we call godotsharp_internal_reload_registered_script
/// </summary>
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]