{"record":{"id":"2f49c5e68db116c1","repo":"stride3d/stride","slug":"destination-length-does-not-match-the-amount-of-indices","errorCode":null,"errorMessage":"destination length does not match the amount of indices contained within the index buffer buffer ({destination.Length} / {IndexBufferHelper.Binding.Count})","messagePattern":"destination length does not match the amount of indices contained within the index buffer buffer \\((.+?) / (.+?)\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/VertexBufferHelper.cs","lineNumber":384,"sourceCode":"        var offset = element.Offset;\n        var count = Binding.Count;\n            \n        fixed (byte* ptrSr = DataInner)\n        {\n            byte* firstElement = ptrSr + offset;\n            reader.Write<TConverter, TSource>(firstElement, count, stride);\n        }\n    }\n\n    public struct CopyAsTriangleList : IReader<Vector3>\n    {\n        public required IndexBufferHelper IndexBufferHelper;\n        \n        public unsafe void Read<TConverter, TSource>(byte* sourcePointer, int elementCount, int stride, Span<Vector3> destination)\n            where TConverter : IConverter<TSource, Vector3> where TSource : unmanaged\n        {\n            if (destination.Length != IndexBufferHelper.Binding.Count)\n                throw new ArgumentException($\"{nameof(destination)} length does not match the amount of indices contained within the index buffer buffer ({destination.Length} / {IndexBufferHelper.Binding.Count})\");\n\n            fixed (Vector3* destPtr = destination)\n            {\n                Vector3* dest = destPtr;\n                if (IndexBufferHelper.Is32Bit(out var indices32, out var indices16))\n                {\n                    foreach (var index in indices32)\n                    {\n                        TConverter.Convert(*(TSource*)(sourcePointer + index * stride), out *dest);\n                        dest++;\n                    }\n                }\n                else\n                {\n                    foreach (var index in indices16)\n                    {\n                        TConverter.Convert(*(TSource*)(sourcePointer + index * stride), out *dest);\n                        dest++;","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/VertexBufferHelper.cs#L366-L402","documentation":"The index-buffer reader validates that the destination Span<Vector3> has exactly as many entries as the index buffer's Binding.Count (number of indices, since each index yields one vertex position). When the spans differ, an ArgumentException is thrown because partial or oversized reads are not supported. Note the message text references the vertex-buffer wording due to a shared message template, but the check compares against index count.","triggerScenarios":"Calling Read on the index reader with a destination span sized differently from the index buffer's binding count, e.g. allocating the span from the vertex count while the index buffer is larger (indexed geometry), or vice versa.","commonSituations":"Reading triangle indices for a mesh where indexCount != vertexCount (typical for indexed meshes); reusing a destination buffer from a previous smaller/larger mesh; off-by-one after deduplicating vertices.","solutions":["Size the destination span to IndexBufferHelper.Binding.Count before calling Read","Recreate the destination array from the actual index buffer count rather than the vertex count","If you intended fewer outputs, adjust the index buffer binding Count accordingly","Log both destination.Length and Binding.Count to confirm which one is stale"],"exampleFix":"// before\nvar positions = new Vector3[vertexCount];\nreader.Read<Color4, Vector3>(ptr, elementCount, stride, positions);\n// after\nvar positions = new Vector3[indexBufferHelper.Binding.Count];\nreader.Read<Color4, Vector3>(ptr, elementCount, stride, positions);","handlingStrategy":"validation","validationCode":"if (destination.Length != indexBufferHelper.Binding.Count)\n    destination = new Vector3[indexBufferHelper.Binding.Count];","typeGuard":"static bool IndexSpanMatches(Vector3[] dest, IndexBufferHelper ib) => dest.Length == ib.Binding.Count;","tryCatchPattern":"try { reader.Read<C, V3>(ptr, count, stride, destination); }\ncatch (ArgumentException ex) { logger.Error(ex, \"Index read destination size mismatch\"); throw; }","preventionTips":["Allocate destination spans from the index buffer count, not vertex count","Remember indexed meshes have indexCount >= vertexCount","Recompute destinations whenever the mesh changes"],"tags":["csharp","graphics","index-buffer","span-length"],"backgroundTag":"shape-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}