From 72775a80bfbcc1b7c7ab06827f1caf6722195a9d Mon Sep 17 00:00:00 2001 From: ackwell Date: Sat, 27 Jan 2024 14:08:56 +1100 Subject: [PATCH] Ignore invalid attributes on export --- Penumbra/Import/Models/Export/MeshExporter.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Penumbra/Import/Models/Export/MeshExporter.cs b/Penumbra/Import/Models/Export/MeshExporter.cs index 5347b87d..1a06acd1 100644 --- a/Penumbra/Import/Models/Export/MeshExporter.cs +++ b/Penumbra/Import/Models/Export/MeshExporter.cs @@ -230,10 +230,19 @@ public class MeshExporter { "targetNames", shapeNames }, }); - var attributes = Enumerable.Range(0, 32) - .Where(index => ((attributeMask >> index) & 1) == 1) - .Select(index => _mdl.Attributes[index]) - .ToArray(); + string[] attributes = []; + var maxAttribute = 31 - BitOperations.LeadingZeroCount(attributeMask); + if (maxAttribute < _mdl.Attributes.Length) + { + attributes = Enumerable.Range(0, 32) + .Where(index => ((attributeMask >> index) & 1) == 1) + .Select(index => _mdl.Attributes[index]) + .ToArray(); + } + else + { + _notifier.Warning($"Invalid attribute data, ignoring."); + } return new MeshData {