Prevents Scripts that have empty paths (external scripts) from getting reloaded.

This commit is contained in:
DE YU 2024-10-12 00:01:41 +08:00
parent 92e51fca72
commit d4f15588f3
2 changed files with 37 additions and 5 deletions

View file

@ -715,11 +715,16 @@ void CSharpLanguage::reload_assemblies(bool p_soft_reload) {
// If someone removes a script from a node, deletes the script, builds, adds a script to the // If someone removes a script from a node, deletes the script, builds, adds a script to the
// same node, then builds again, the script might have no path and also no script_class. In // same node, then builds again, the script might have no path and also no script_class. In
// that case, we can't (and don't need to) reload it. // that case, we can't (and don't need to) reload it.
if (scr->get_path().is_empty() && !scr->valid) {
bool is_path_empty = scr->get_path().is_empty();
if (is_path_empty && !scr->valid) {
continue; continue;
} }
to_reload.push_back(scr); if (!is_path_empty) {
to_reload.push_back(scr);
}
// Script::instances are deleted during managed object disposal, which happens on domain finalize. // Script::instances are deleted during managed object disposal, which happens on domain finalize.
// Only placeholders are kept. Therefore we need to keep a copy before that happens. // Only placeholders are kept. Therefore we need to keep a copy before that happens.

View file

@ -23,6 +23,23 @@ public static partial class ScriptManagerBridge
Debug.Assert(!scriptType.IsGenericTypeDefinition, $"A generic type definition must never be added to the script type map. Type: {scriptType}."); Debug.Assert(!scriptType.IsGenericTypeDefinition, $"A generic type definition must never be added to the script type map. Type: {scriptType}.");
var duplicateScript = _scriptTypeMap.ContainsKey(scriptPtr);
var duplicateType = _typeScriptMap.ContainsKey(scriptType);
if (duplicateScript && duplicateType)
{
throw new ArgumentException($"Duplicate script type & pointer: {scriptType}({scriptPtr}).");
}
if (duplicateScript)
{
throw new ArgumentException($"Duplicate script pointer: {scriptType}({scriptPtr}).");
}
if (duplicateType)
{
throw new ArgumentException($"Duplicate script type: {scriptType}({scriptPtr}).");
}
_scriptTypeMap.Add(scriptPtr, scriptType); _scriptTypeMap.Add(scriptPtr, scriptType);
_typeScriptMap.Add(scriptType, scriptPtr); _typeScriptMap.Add(scriptType, scriptPtr);
@ -34,14 +51,24 @@ public static partial class ScriptManagerBridge
public void Remove(IntPtr scriptPtr) public void Remove(IntPtr scriptPtr)
{ {
if (_scriptTypeMap.Remove(scriptPtr, out Type? scriptType)) if (!_scriptTypeMap.Remove(scriptPtr, out var scriptType))
_ = _typeScriptMap.Remove(scriptType); {
return;
}
_typeScriptMap.Remove(scriptType);
} }
public bool RemoveByScriptType(Type scriptType, out IntPtr scriptPtr) public bool RemoveByScriptType(Type scriptType, out IntPtr scriptPtr)
{ {
if (_typeScriptMap.TryGetValue(scriptType, out scriptPtr) && !_scriptTypeMap.ContainsKey(scriptPtr))
{
throw new ArgumentException($"Unable to find script pointer for script type: {scriptType}");
}
if (_typeScriptMap.Remove(scriptType, out scriptPtr)) if (_typeScriptMap.Remove(scriptType, out scriptPtr))
return _scriptTypeMap.Remove(scriptPtr); {
_scriptTypeMap.Remove(scriptPtr);
return true;
}
return false; return false;
} }