Gracefully handle integer UV channels during GLB export

* Resolves #1811
This commit is contained in:
ds5678 2025-07-15 18:13:50 -07:00
parent ab7d9b59cf
commit e9db99e07e
2 changed files with 33 additions and 1 deletions

View File

@ -185,6 +185,6 @@ public readonly record struct MeshData(
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
private static T TryGetAtIndex<T>(T[]? array, uint index) where T : struct
{
return array is null ? default : array[index];
return array is null or { Length: 0 } ? default : array[index];
}
}

View File

@ -0,0 +1,32 @@
using AssetRipper.SourceGenerated.Extensions;
namespace AssetRipper.Tests;
internal class MeshDataTests
{
[Test]
public void AccessingNullUV2DoesNotThrow()
{
MeshData meshData = MeshData.CreateTriangleMesh() with
{
UV2 = null
};
Assert.DoesNotThrow(() =>
{
meshData.TryGetUV2AtIndex(0);
});
}
[Test]
public void AccessingEmptyUV2DoesNotThrow()
{
MeshData meshData = MeshData.CreateTriangleMesh() with
{
UV2 = []
};
Assert.DoesNotThrow(() =>
{
meshData.TryGetUV2AtIndex(0);
});
}
}