From 0444c66e01f6130afe2b5d05f19cbaf3485c8a99 Mon Sep 17 00:00:00 2001 From: Kythyria Tieran Date: Mon, 14 Jun 2021 22:55:16 +0100 Subject: [PATCH] Throw on errors caused by overlarge meshes. --- PD2ModelParser/Importers/GltfImporter.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/PD2ModelParser/Importers/GltfImporter.cs b/PD2ModelParser/Importers/GltfImporter.cs index f854920..901fd82 100644 --- a/PD2ModelParser/Importers/GltfImporter.cs +++ b/PD2ModelParser/Importers/GltfImporter.cs @@ -460,6 +460,13 @@ public void AppendVertices(IEnumerable vertices) public static MeshData FromGltfMesh(GLTF.Mesh mesh) { + + var vcount = mesh.Primitives.Select(prim => prim.VertexAccessors["POSITION"].Count).Sum(); + if (vcount >= ushort.MaxValue) + { + throw new Exception($"Too many vertices ({vcount}) in mesh {mesh.Name}. Limit is 65535"); + } + var attribsUsed = mesh.Primitives.First().VertexAccessors.Select(i => i.Key).OrderBy(i => i); var ok = mesh.Primitives.Select(i => i.VertexAccessors.Keys.OrderBy(j => j)).Aggregate(true, (acc, curr) => acc && curr.SequenceEqual(attribsUsed)); if (!ok)