stride3d/stride · error · ArgumentException
destination length does not match the amount of indices cont
Error message
destination length does not match the amount of indices contained within the index buffer buffer ({destination.Length} / {IndexBufferHelper.Binding.Count}) What it means
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.
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
Example fix
// before var positions = new Vector3[vertexCount]; reader.Read<Color4, Vector3>(ptr, elementCount, stride, positions); // after var positions = new Vector3[indexBufferHelper.Binding.Count]; reader.Read<Color4, Vector3>(ptr, elementCount, stride, positions);
Defensive patterns
Strategy: validation
Validate before calling
if (destination.Length != indexBufferHelper.Binding.Count)
destination = new Vector3[indexBufferHelper.Binding.Count]; Type guard
static bool IndexSpanMatches(Vector3[] dest, IndexBufferHelper ib) => dest.Length == ib.Binding.Count;
Try / catch
try { reader.Read<C, V3>(ptr, count, stride, destination); }
catch (ArgumentException ex) { logger.Error(ex, "Index read destination size mismatch"); throw; } Prevention
- Allocate destination spans from the index buffer count, not vertex count
- Remember indexed meshes have indexCount >= vertexCount
- Recompute destinations whenever the mesh changes
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- destination length does not match the amount of vertices con
- Invalid Z slice index
- MipLevels must be <= {maxMips}
- Width/Height/Depth must be power of 2
- Image format not supported
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2f49c5e68db116c1.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexBufferHelper.cs:384
var offset = element.Offset;
var count = Binding.Count;
fixed (byte* ptrSr = DataInner)
{
byte* firstElement = ptrSr + offset;
reader.Write<TConverter, TSource>(firstElement, count, stride);
}
}
public struct CopyAsTriangleList : IReader<Vector3>
{
public required IndexBufferHelper IndexBufferHelper;
public unsafe void Read<TConverter, TSource>(byte* sourcePointer, int elementCount, int stride, Span<Vector3> destination)
where TConverter : IConverter<TSource, Vector3> where TSource : unmanaged
{
if (destination.Length != IndexBufferHelper.Binding.Count)
throw new ArgumentException($"{nameof(destination)} length does not match the amount of indices contained within the index buffer buffer ({destination.Length} / {IndexBufferHelper.Binding.Count})");
fixed (Vector3* destPtr = destination)
{
Vector3* dest = destPtr;
if (IndexBufferHelper.Is32Bit(out var indices32, out var indices16))
{
foreach (var index in indices32)
{
TConverter.Convert(*(TSource*)(sourcePointer + index * stride), out *dest);
dest++;
}
}
else
{
foreach (var index in indices16)
{
TConverter.Convert(*(TSource*)(sourcePointer + index * stride), out *dest);
dest++;View on GitHub (pinned to 96fad776d2)