Fixed stackoverflow caused by ParseDerived due to GetDerivedNonAbstract not returning abstract types

This commit is contained in:
EvilFactory
2024-03-29 11:32:35 -03:00
parent ee337e4f18
commit 7dc75c6dd2

View File

@@ -1,4 +1,5 @@
#nullable enable
using Barotrauma.Debugging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -55,7 +56,13 @@ namespace Barotrauma
if (list.Length == 0)
{
return ImmutableArray<Type>.Empty; // No types, don't add to cache
}
}
if (!TypeSearchCache.TryAdd(typeName, list))
{
DebugConsoleCore.Log($"ReflectionUtils.AddNonAbstractAssemblyTypes(): Error while adding to quick lookup cache.");
}
return list;
}
@@ -107,7 +114,7 @@ namespace Barotrauma
public static void ResetCache()
{
CachedNonAbstractTypes.Clear();
CachedNonAbstractTypes.TryAdd(typeof(ReflectionUtils).Assembly, typeof(ReflectionUtils).Assembly.GetTypes().ToImmutableArray());
CachedNonAbstractTypes.TryAdd(typeof(ReflectionUtils).Assembly, typeof(ReflectionUtils).Assembly.GetTypes().Where(t => !t.IsAbstract).ToImmutableArray());
TypeSearchCache.Clear();
}