fix: fix a potential ArgumentOutOfRangeException that could occur when changing the FontAsset in TextMeshPro

close #327
This commit is contained in:
mob-sakai
2025-04-04 10:10:31 +09:00
parent 75ed355e27
commit 909281c66b
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
@@ -110,10 +111,11 @@ namespace Coffee.UIEffectInternal
dst.Clear();
for (var i = 0; i < vertexCount; i++)
{
dst.AddVert(positions[i], colors[i], uv0[i], uv1[i], normals[i], tangents[i]);
dst.AddVert(positions.GetOrDefault(i), colors.GetOrDefault(i), uv0.GetOrDefault(i), uv1.GetOrDefault(i),
normals.GetOrDefault(i), tangents.GetOrDefault(i));
}
for (var i = 0; i < indexCount; i += 3)
for (var i = 0; i < indexCount - 2; i += 3)
{
dst.AddTriangle(indices[i], indices[i + 1], indices[i + 2]);
}
@@ -126,5 +128,12 @@ namespace Coffee.UIEffectInternal
InternalListPool<Color32>.Return(ref colors);
InternalListPool<int>.Return(ref indices);
}
private static T GetOrDefault<T>(this List<T> self, int index)
{
return 0 <= index && index < self.Count
? self[index]
: default;
}
}
}