Skip to content

Commit

Permalink
Fixed stackoverflow caused by ParseDerived due to GetDerivedNonAbstra…
Browse files Browse the repository at this point in the history
…ct not returning abstract types
  • Loading branch information
evilfactory committed Mar 29, 2024
1 parent ee337e4 commit 7dc75c6
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Libraries/BarotraumaLibs/BarotraumaCore/Utils/ReflectionUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#nullable enable
using Barotrauma.Debugging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down Expand Up @@ -55,7 +56,13 @@ public static IEnumerable<Type> GetDerivedNonAbstract<T>()
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;
}

Expand Down Expand Up @@ -107,7 +114,7 @@ public static void RemoveAssemblyFromCache(Assembly assembly)
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();
}

Expand Down

0 comments on commit 7dc75c6

Please sign in to comment.