Fix threading issues introduced by #117

This commit is contained in:
EvilFactory
2022-11-22 14:10:13 -03:00
parent ee1a87be19
commit aee83bdf74
@@ -1,4 +1,4 @@
#nullable enable #nullable enable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable; using System.Collections.Immutable;
@@ -22,14 +22,7 @@ namespace Barotrauma
} }
#warning TODO: Add safety checks in case an assembly is unloaded without being removed from the cache. #warning TODO: Add safety checks in case an assembly is unloaded without being removed from the cache.
return cachedNonAbstractTypes.Values.SelectMany(s => s.Where(t => t.IsSubclassOf(typeof(T))));
List<Type> types = new List<Type>();
foreach (var typearr in cachedNonAbstractTypes)
{
types = types.Concat(typearr.Value.Where(t => t.IsSubclassOf(typeof(T)))).ToList();
}
return types;
} }
/// <summary> /// <summary>
@@ -53,7 +46,9 @@ namespace Barotrauma
try try
{ {
if (!cachedNonAbstractTypes.TryAdd(assembly, assembly.GetTypes().Where(t => !t.IsAbstract).ToImmutableArray())) if (!cachedNonAbstractTypes.TryAdd(assembly, assembly.GetTypes().Where(t => !t.IsAbstract).ToImmutableArray()))
{
DebugConsole.LogError($"ReflectionUtils::AddNonAbstractAssemblyTypes() | Unable to add types from Assembly to cache."); DebugConsole.LogError($"ReflectionUtils::AddNonAbstractAssemblyTypes() | Unable to add types from Assembly to cache.");
}
} }
catch (ReflectionTypeLoadException e) catch (ReflectionTypeLoadException e)
{ {