stride3d/stride · error · ArgumentException
Element size must be greater than zero for structured…
Error message
Element size must be greater than zero for structured buffers
What it means
A D3D11 structured buffer requires a nonzero element stride (StructureByteStride) so the hardware can index elements. When a Buffer is initialized with BufferFlags.StructuredBuffer and StructureByteStride <= 0, InitializeFromImpl throws ArgumentException because D3D11 cannot create the buffer descriptor without a valid stride.
Solutions
- Set StructureByteStride to the size of one element (e.g. sizeof(MyStruct) or Marshal.SizeOf<T>()) in the buffer description.
- If you do not need typed element indexing, use BufferFlags.RawBuffer instead of StructuredBuffer.
- Validate the description before creating the buffer to fail with a clearer message.
Example fix
// before var buffer = Buffer.New(device, byteCount * 4, BufferFlags.StructuredBuffer); // after var buffer = Buffer.New(device, byteCount, BufferFlags.StructuredBuffer, structureByteStride: sizeof(float));
Defensive patterns
Strategy: validation
Validate before calling
if (desc.BufferFlags.HasFlag(BufferFlags.StructuredBuffer) && desc.StructureByteStride <= 0)
throw new InvalidOperationException("Structured buffers require a positive StructureByteStride"); Type guard
bool IsValidStructuredBuffer(BufferDescription d) => !d.BufferFlags.HasFlag(BufferFlags.StructuredBuffer) || d.StructureByteStride > 0;
Try / catch
try { buffer = Buffer.New(device, size, BufferFlags.StructuredBuffer); }
catch (ArgumentException ex) when (ex.Message.Contains("Element size")) { /* fix stride and retry */ } Prevention
- Always set StructureByteStride when using StructuredBuffer flag
- Prefer RawBuffer if element size is unknown
- Wrap buffer creation in a factory that validates descriptions
When it happens
Trigger: Calling Buffer.New / Buffer initialization with BufferFlags.StructuredBuffer set while leaving StructureByteStride at its default 0 or passing a negative value.
Common situations: Declaring only the StructuredBuffer flag in the buffer description without filling in the stride field; copying a raw-buffer (RawBuffer) description and adding the StructuredBuffer flag; forgetting that unlike raw buffers, structured buffers need explicit element size.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Cannot use .
- Expecting a Buffer supporting UAV
- The length of the destination data buffer is larger than…
- The length of the source data to upload is larger than the…
- Offsets are only supported for Textures declared with
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/338d33a99ec612f7.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Direct3D11/Buffer.Direct3D11.cs:121
bufferDesc.BindFlags |= (uint) BindFlag.IndexBuffer;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.VertexBuffer))
bufferDesc.BindFlags |= (uint) BindFlag.VertexBuffer;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.RenderTarget))
bufferDesc.BindFlags |= (uint) BindFlag.RenderTarget;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.ShaderResource))
bufferDesc.BindFlags |= (uint) BindFlag.ShaderResource;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.UnorderedAccess))
bufferDesc.BindFlags |= (uint) BindFlag.UnorderedAccess;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.StructuredBuffer))
{
bufferDesc.MiscFlags |= (uint) BufferFlags.StructuredBuffer;
if (bufferDescription.StructureByteStride <= 0)
throw new ArgumentException("Element size must be greater than zero for structured buffers");
}
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.RawBuffer))
bufferDesc.MiscFlags |= (uint) ResourceMiscFlag.BufferAllowRawViews;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.ArgumentBuffer))
bufferDesc.MiscFlags |= (uint) ResourceMiscFlag.DrawindirectArgs;
if (bufferDescription.BufferFlags.HasFlag(BufferFlags.StreamOutput))
bufferDesc.BindFlags |= (uint) BindFlag.StreamOutput;
if (bufferDesc.Usage == Silk.NET.Direct3D11.Usage.Dynamic)
{
bufferDesc.CPUAccessFlags = (uint) CpuAccessFlag.Write;
if (bufferDesc.BindFlags == 0)
bufferDesc.BindFlags = (uint) BindFlag.ConstantBuffer;
}
View on GitHub (pinned to 96fad776d2)