stride3d/stride · error · ArgumentException
The length and stride of destination does not match the…
Error message
The length and stride of destination does not match the vertices required ({destination.Length / DestStride} / {vertexCount}) What it means
Thrown by InterleavedParameters when the destination buffer length divided by the destination stride does not equal the vertex count. The library requires the destination span to hold exactly vertexCount vertices of destStride bytes each — no more, no less. (Note the interpolated string references the DestStride field before it is assigned, so it may render 0 in the message.)
Solutions
- Resize the destination span to exactly vertexCount * destStride bytes
- Verify destStride equals the sum of the destination element format sizes in bytes
- Pass a vertexCount consistent with both source and destination buffer sizes
- Check the source check passes too — fix source and destination together
Example fix
// before var dest = new byte[source.Length]; // wrong: source stride != dest stride VertexBufferHelper.Interleave(source, srcStride, dest, destStride, vertexCount); // after var dest = new byte[vertexCount * destStride]; VertexBufferHelper.Interleave(source, srcStride, dest, destStride, vertexCount);
Defensive patterns
Strategy: validation
Validate before calling
if (destination.Length != vertexCount * destStride)
throw new ArgumentException("destination must be exactly vertexCount * destStride bytes"); Try / catch
try { Interleave(...); } catch (ArgumentException ex) { log(ex.Message); reallocateBuffers(); } Prevention
- Size destination as vertexCount * destStride, never copy the source length
- Derive destStride by summing destination element Format.SizeInBytes
- Keep vertexCount as a single shared variable for both buffers
When it happens
Trigger: Calling VertexBufferHelper interleave APIs (e.g. with an InterleavedParameters or its constructor) with a destination Span<byte> whose length is not exactly vertexCount * destStride — e.g. allocating a buffer sized for the source stride instead of the destination stride, or passing a vertexCount that disagrees with the buffer sizes.
Common situations: Migrating a vertex layout to a new format where the destination element set has a different stride; computing buffer size with Marshal.SizeOf of the wrong struct; off-by-one vertex counts when building partial meshes.
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 source does not match the vertices…
- 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/f54d08d6148ebe9a.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexBufferHelper.cs:437
{
byte* end = sourcePointer + elementCount * stride;
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();View on GitHub (pinned to 96fad776d2)