Skip to content

Commit 5a919d9

Browse files
authored
Fix bugs in HasCustomAttribute affecting performance (#405)
1 parent 6013b89 commit 5a919d9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Cpp2IL.Core/Model/Contexts/HasCustomAttributes.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ private void InitPre29AttributeGeneratorAnalysis(int rangeIndex)
137137
{
138138
ulong generatorPtr;
139139
if (AppContext.MetadataVersion < 27)
140+
{
141+
if (rangeIndex < 0)
142+
{
143+
RawIl2CppCustomAttributeData = Array.Empty<byte>();
144+
return;
145+
}
146+
140147
try
141148
{
142149
generatorPtr = AppContext.Binary.GetCustomAttributeGenerator(rangeIndex);
@@ -147,6 +154,7 @@ private void InitPre29AttributeGeneratorAnalysis(int rangeIndex)
147154
RawIl2CppCustomAttributeData = Array.Empty<byte>();
148155
return;
149156
}
157+
}
150158
else
151159
{
152160
var baseAddress = CustomAttributeAssembly.CodeGenModule!.customAttributeCacheGenerator;
@@ -204,7 +212,7 @@ public void AnalyzeCustomAttributeData(bool allowAnalysis = true)
204212

205213
//Basically, extract actions from the analysis, and compare with the type list we have to resolve parameters and populate the CustomAttributes list.
206214

207-
foreach (var il2CppType in AttributeTypes!) //Assert nonnull because we're pre-29 at this point
215+
foreach (var il2CppType in AttributeTypes ?? []) //Can be null for injected objects
208216
{
209217
var typeDef = il2CppType.AsClass();
210218
var attributeTypeContext = AppContext.ResolveContextForType(typeDef) ?? throw new("Unable to find type " + typeDef.FullName);

0 commit comments

Comments
 (0)