stride3d/stride · error · ArgumentException
The vertex stride is not a multiple of 4 bytes
Error message
The vertex stride is not a multiple of 4 bytes
What it means
VertexElementValidator.Validate requires the vertex stride to be a multiple of 4 bytes, matching GPU vertex-buffer alignment requirements. A stride of e.g. 6 or 10 bytes is rejected with ArgumentException before any buffer is created.
Solutions
- Add a padding element (e.g. an R8G8B8A8 or an unused component) so the stride is a multiple of 4
- Widen an undersized element format (e.g. R8_UInt to R32_UInt)
- Recompute the stride as the sum of element Format.SizeInBytes and pad to the next multiple of 4
Example fix
// before // elements: R16G16 (4) + R16 (2) => stride 6 // after elements: R16G16 (4) + R32 (4) => stride 8
Defensive patterns
Strategy: validation
Validate before calling
int stride = elements.Sum(e => e.Format.SizeInBytes);
if (stride <= 0 || (stride & 3) != 0)
throw new ArgumentException("Vertex stride must be a positive multiple of 4 bytes"); Try / catch
try { VertexElementValidator.Validate(stride, elements); } catch (ArgumentException ex) { padLayoutTo4Bytes(); } Prevention
- Pad vertex layouts to a 4-byte-aligned stride
- Avoid odd-sized trailing elements like a lone R8
- Compute stride from Format.SizeInBytes sums, not from C# struct size
When it happens
Trigger: Building a VertexBufferBinding/vertex declaration whose summed element sizes total a non-multiple of 4, e.g. three R16G16 elements (6 bytes) or adding a single R8 element to a 9-byte stride.
Common situations: Compact packed vertex layouts (byte-based colors, 16-bit normals) that don't pad to 4 bytes; hand-computed strides missing padding.
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
- Custom strides is not supported with packed PixelFormats
- The offset of the is not a multiple of 4 bytes
- A overlaps with another element. Check the element's offset
- A region can only be specified for Textures with…
- Cannot create a Texture View with flags
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/43366ae40f13bf85.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/VertexElementValidator.cs:65
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="vertexStride"/> is not a positive number greater than zero.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown if:
/// <list type="bullet">
/// <item><paramref name="vertexStride"/> is not a multiple of 4 bytes.</item>
/// <item>Any Vertex Element extends beyond the bounds of the vertex stride.</item>
/// <item>Any Vertex Element has an offset that is not a multiple of 4 bytes.</item>
/// <item>Duplicate Vertex Elements are found with the same semantic name and index.</item>
/// <item>Any Vertex Element overlaps with another element.</item>
/// </list>
/// </exception>
internal static void Validate(int vertexStride, VertexElement[] elements)
{
ArgumentOutOfRangeException.ThrowIfNegativeOrZero(vertexStride);
if ((vertexStride & 3) != 0)
throw new ArgumentException($"The vertex stride is not a multiple of 4 bytes", nameof(vertexStride));
// For checking overlaps, we use an array to track occupied bytes
var overlapCheckArray = new int[vertexStride];
for (int i = 0; i < overlapCheckArray.Length; i++)
overlapCheckArray[i] = -1;
int totalOffset = 0;
for (int elementIndex = 0; elementIndex < elements.Length; elementIndex++)
{
// Compute the offset for this element
int elementOffset = elements[elementIndex].AlignedByteOffset;
if (elementOffset == VertexElement.AppendAligned)
{
elementOffset = elementIndex == 0 ? 0 : totalOffset + elements[elementIndex - 1].Format.SizeInBytes;
}
totalOffset = elementOffset;
// Validate the element offsetView on GitHub (pinned to 96fad776d2)