Skip to content

Commit 084605a

Browse files
committed
fix: Fixed ArgumentException occuring on domain reload
1 parent e3ad7e6 commit 084605a

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Editor/GenericTypesAnalyzer/DictInitializer.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using GeneratedTypesDatabase;
88
using GenericUnityObjects.Util;
99
using UnityEditor;
10+
using UnityEngine;
1011
using UnityEngine.Assertions;
1112
using Object = UnityEngine.Object;
1213

@@ -90,12 +91,24 @@ private static Dictionary<Type[], Type> CreateConcreteClassesDict(GenericTypeInf
9091

9192
foreach (ConcreteClass concreteClass in concreteClasses)
9293
{
94+
if (!TryGetConcreteClassType(genericTypeInfo, concreteClass, out Type value))
95+
continue;
96+
97+
// BUG: This somehow happened once. It started throwing exception after I commented out a generic class not related to genericTypeInfo nor the concrete class in question.
98+
// Would be good to have the steps to reproduce.
99+
if (value.BaseType?.GetGenericTypeDefinition() != genericTypeInfo.Type)
100+
{
101+
Debug.LogWarning($"The concrete class for type {value.BaseType} was added to the generic type {genericTypeInfo.Type.Name}. " +
102+
"This shouldn't happen. If you have steps to reproduce the bug, please report it.");
103+
104+
GenerationDatabase<TObject>.RemoveConcreteClass(genericTypeInfo, concreteClass);
105+
continue;
106+
}
107+
93108
var key = GetConcreteClassArguments(concreteClass);
94-
95-
if (TryGetConcreteClassType(genericTypeInfo, concreteClass, out Type value))
96-
concreteClassesDict.Add(key, value);
109+
concreteClassesDict.Add(key, value);
97110
}
98-
111+
99112
return concreteClassesDict;
100113
}
101114

0 commit comments

Comments
 (0)