From aee83bdf74ff42be0d6e2f21a56cdfcb2f19cd23 Mon Sep 17 00:00:00 2001 From: EvilFactory Date: Tue, 22 Nov 2022 14:10:13 -0300 Subject: [PATCH] Fix threading issues introduced by #117 --- .../SharedSource/Utils/ReflectionUtils.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/Barotrauma/BarotraumaShared/SharedSource/Utils/ReflectionUtils.cs b/Barotrauma/BarotraumaShared/SharedSource/Utils/ReflectionUtils.cs index 7b6c6a26f..ee48a1eb3 100644 --- a/Barotrauma/BarotraumaShared/SharedSource/Utils/ReflectionUtils.cs +++ b/Barotrauma/BarotraumaShared/SharedSource/Utils/ReflectionUtils.cs @@ -1,4 +1,4 @@ -#nullable enable +#nullable enable using System; using System.Collections.Generic; 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. - - List types = new List(); - foreach (var typearr in cachedNonAbstractTypes) - { - types = types.Concat(typearr.Value.Where(t => t.IsSubclassOf(typeof(T)))).ToList(); - } - - return types; + return cachedNonAbstractTypes.Values.SelectMany(s => s.Where(t => t.IsSubclassOf(typeof(T)))); } /// @@ -53,7 +46,9 @@ namespace Barotrauma try { if (!cachedNonAbstractTypes.TryAdd(assembly, assembly.GetTypes().Where(t => !t.IsAbstract).ToImmutableArray())) + { DebugConsole.LogError($"ReflectionUtils::AddNonAbstractAssemblyTypes() | Unable to add types from Assembly to cache."); + } } catch (ReflectionTypeLoadException e) {