stride3d/stride · error · ArgumentException
The length and stride of source does not match the vertices…
Error message
The length and stride of source does not match the vertices required ({source.Length / SourceStride} / {vertexCount}) What it means
Thrown by InterleavedParameters when the source buffer length divided by the source stride does not equal the vertex count. The source span must contain exactly vertexCount vertices of sourceStride bytes each.
Solutions
- Resize the source span to exactly vertexCount * sourceStride bytes
- Recompute sourceStride from the actual source vertex declaration
- Pass the correct vertexCount matching the source data actually available
- Slice the buffer to the exact vertex range being interleaved
Example fix
// before var src = vertexData.AsSpan(0, (int)(vertexData.Length * 0.5f)); helper.Interleave(src, srcStride, dest, destStride, totalVertexCount); // after var src = vertexData.AsSpan(0, totalVertexCount * srcStride); helper.Interleave(src, srcStride, dest, destStride, totalVertexCount);
Defensive patterns
Strategy: validation
Validate before calling
if (source.Length != vertexCount * sourceStride)
throw new ArgumentException("source must be exactly vertexCount * sourceStride bytes"); Try / catch
try { Interleave(...); } catch (ArgumentException ex) { log(ex.Message); reloadVertexData(); } Prevention
- Slice source spans with vertexCount * sourceStride as the exact length
- Recompute sourceStride whenever the source vertex declaration changes
- Validate mesh vertex counts after loading
When it happens
Trigger: Calling the interleave API with a source Span<byte> whose length is not exactly vertexCount * sourceStride — e.g. reading fewer bytes than the full vertex stream from a file, or passing a stale vertexCount after the mesh changed.
Common situations: Loading a subset of vertices but passing the full vertexCount; packing raw vertex data whose stride was computed from an older vertex declaration; slicing a larger buffer with an incorrect length.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- The length and stride of destination does not match the…
- Invalid Z slice index
- Custom strides is not supported with packed PixelFormats
- The Texture must be a Render Target
- Binding describes an array larger than dataOuter
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/5f5ddfd7bc4ea17d.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexBufferHelper.cs:439
T* dest = ptrDest;
for (; sourcePointer < end; sourcePointer += stride, dest++)
TConverter.Convert(*(TSource*)sourcePointer, out *dest);
}
}
}
private readonly ref struct InterleavedParameters
{
public readonly Span<byte> Source, Destination;
public readonly int SourceStride, DestStride;
public readonly int VertexCount;
public InterleavedParameters(Span<byte> source, Span<byte> destination, int sourceStride, int destStride, int vertexCount)
{
if (destination.Length / destStride != vertexCount)
throw new ArgumentException($"The length and stride of {nameof(destination)} does not match the vertices required ({destination.Length / DestStride} / {vertexCount})");
if (source.Length / sourceStride != vertexCount)
throw new ArgumentException($"The length and stride of {nameof(source)} does not match the vertices required ({source.Length / SourceStride} / {vertexCount})");
Source = source;
Destination = destination;
SourceStride = sourceStride;
DestStride = destStride;
VertexCount = vertexCount;
}
}
/// <example>
/// Implementing <see cref="Copy{TSemantic,TValue}"/> manually:
/// <code>
/// <![CDATA[
/// Model.Meshes[0].Draw.VertexBuffers[0].AsReadable(Services, out VertexBufferHelper helper, out int count);
/// var vertexPositions = new Vector3[count];
/// var myReader = new CopyTo();
/// helper.Read<PositionSemantic, Vector3, CopyTo>(vertexPositions, myReader);
/// View on GitHub (pinned to 96fad776d2)