stride3d/stride · error · ArgumentOutOfRangeException
The length of vertex buffer
Error message
The length of vertex buffer [{0}] doesn't match the expected length with the vertex stride [{1}] What it means
The byte[] overload validates that buffer length is an exact multiple of the vertex stride; if not it throws ArgumentOutOfRangeException('vertexBufferData') with a message showing the buffer length and expected length. This guards against reading garbage when the raw buffer is truncated, padded, or described by the wrong stride.
Solutions
- Verify buffer length == vertexCount * vertexStride and trim padding/extra bytes.
- Ensure the VertexDeclaration matches the actual packed layout (correct VertexStride).
- Confirm you are passing the vertex buffer, not the index buffer, and that the source exporter packs vertices contiguously.
Example fix
// before var result = VertexHelper.GenerateMultiTextureCoordinates(declaration, packedBytes); // packedBytes.Length = 100, stride = 32 // after var usableLength = packedBytes.Length - (packedBytes.Length % declaration.VertexStride); Array.Resize(ref packedBytes, usableLength); var result = VertexHelper.GenerateMultiTextureCoordinates(declaration, packedBytes);
Defensive patterns
Strategy: validation
Validate before calling
var vertexCount = vertexBufferData.Length / vertexStride;
if (vertexCount == 0 || vertexBufferData.Length % vertexStride != 0)
throw new InvalidOperationException($"Buffer length {vertexBufferData.Length} is not a multiple of stride {vertexStride}"); Try / catch
try { var r = VertexHelper.GenerateMultiTextureCoordinates(decl, bytes); } catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "vertexBufferData") { /* fix buffer packing or stride */ } Prevention
- Always verify length % stride == 0 when importing raw vertex data
- Match the declaration's VertexStride to the exporter's actual packing
- Never pad or interleave extra bytes into vertex buffers without updating the declaration
When it happens
Trigger: vertexBufferData.Length is not divisible by vertexStride — e.g. byteCount = 100 with stride 32 (indices, extra trailing bytes, or interleaved data not accounted for).
Common situations: Manually packed vertex data with extra padding; passing index data instead of vertex data; stride mismatch after changing the vertex layout without regenerating the buffer; off-by-one when exporting from a tool.
Related errors
- Cannot specify the format for more than 8 Render Targets.
- indexCountArg must be >= 0
- Invalid array slice index
- Invalid mipmap level
- Invalid Texture data length
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/390963d5be6e35b5.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexHelper.cs:70
/// <exception cref="System.ArgumentNullException">
/// vertexDeclaration
/// or
/// vertexBufferData
/// </exception>
/// <remarks>The original vertex buffer must contain at least a TEXCOORD[0-9] attribute in order for this method to work.
/// This method will copy the value of the first existing TEXCOORD found in the vertex buffer to the newly created TEXCOORDS.</remarks>
public static unsafe VertexTransformResult GenerateMultiTextureCoordinates(VertexDeclaration vertexDeclaration, byte[] vertexBufferData, int vertexStride = 0, int maxTexcoord = 9)
{
if (vertexDeclaration == null) throw new ArgumentNullException("vertexDeclaration");
if (vertexBufferData == null) throw new ArgumentNullException("vertexBufferData");
if (vertexStride == 0)
{
vertexStride = vertexDeclaration.VertexStride;
}
var vertexCount = ((int)(vertexBufferData.Length / vertexStride));
if (vertexBufferData.Length != (vertexCount * vertexStride))
{
throw new ArgumentOutOfRangeException("vertexBufferData", "The length of vertex buffer [{0}] doesn't match the expected length with the vertex stride [{1}]".ToFormat(vertexBufferData.Length, vertexCount * vertexStride));
}
fixed (void* vertexBufferPtr = vertexBufferData)
return GenerateMultiTextureCoordinates(vertexDeclaration, (nint)vertexBufferPtr, vertexCount, 0, vertexStride, maxTexcoord);
}
/// <summary>
/// Generates multi texture coordinates for an existing vertex buffer. See remarks.
/// </summary>
/// <param name="transform">The result of a previous transform.</param>
/// <param name="vertexStride">The vertex stride.</param>
/// <param name="maxTexcoord">The maximum texcoord.</param>
/// <returns>A new vertex buffer with additional texture coordinates.</returns>
/// <remarks>The original vertex buffer must contain at least a TEXCOORD[0-9] attribute in order for this method to work.
/// This method will copy the value of the first existing TEXCOORD found in the vertex buffer to the newly created TEXCOORDS.</remarks>
public static VertexTransformResult GenerateMultiTextureCoordinates(VertexTransformResult transform, int vertexStride = 0, int maxTexcoord = 9)
{
return GenerateMultiTextureCoordinates(transform.Layout, transform.VertexBuffer, vertexStride, maxTexcoord);View on GitHub (pinned to 96fad776d2)