Skip to content

Commit 464e043

Browse files
committed
fix: Fixed ArgumentOutOfRange exception when trying to find a custom script icon
1 parent cde98f2 commit 464e043

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Editor/Util/ExampleInstaller.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ public static void AddConcreteClasses<TObject>(KeyValuePair<Type, Type[]>[] type
2626
}
2727
}
2828

29-
AssetDatabase.Refresh();
30-
3129
PersistentStorage.ExecuteOnScriptsReload(afterAddingTypes);
30+
AssetDatabase.Refresh();
3231
}
3332
}
3433
}

Editor/Util/IconFinder.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,31 @@ private static bool TryGetCustomIcon(string assetPath, out Texture2D customIcon)
5252
return false;
5353
}
5454

55-
string guid = GetGUIDFromIconLine(iconLine);
55+
if (!GetGUIDFromIconLine(iconLine, out string guid))
56+
{
57+
customIcon = null;
58+
return false;
59+
}
60+
5661
string texturePath = AssetDatabase.GUIDToAssetPath(guid);
5762
customIcon = AssetDatabase.LoadAssetAtPath<Texture2D>(texturePath);
5863
Assert.IsNotNull(customIcon);
5964
return true;
6065
}
6166

62-
private static string GetGUIDFromIconLine(string iconLine)
67+
private static bool GetGUIDFromIconLine(string iconLine, out string guid)
6368
{
6469
int guidIndex = iconLine.IndexOf("guid: ", StringComparison.Ordinal);
65-
return iconLine.Substring(guidIndex + 6, 32);
70+
71+
// There may be instanceID instead of guid on the icon line.
72+
if (guidIndex == -1 || iconLine.Length < guidIndex + 37)
73+
{
74+
guid = null;
75+
return false;
76+
}
77+
78+
guid = iconLine.Substring(guidIndex + 6, 32);
79+
return true;
6680
}
6781

6882
private static string GetIconLine(string assetPath)

0 commit comments

Comments
 (0)