Merge pull request #99798 from preslavnpetrov/master

[C#] Fix thread deadlock when using a worker thread to load a script with a generic base class
This commit is contained in:
Thaddeus Crews
2025-07-09 11:33:20 -05:00

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]