stride3d/stride · error · ArgumentException
Expecting a Buffer supporting UAV
Error message
Expecting a Buffer supporting UAV
What it means
ClearReadWrite(Buffer, Vector4) clears a read-write buffer through its D3D11 UAV. If the Buffer was not created with the UnorderedAccess flag, its NativeUnorderedAccessView handle is null and the method throws an ArgumentException. The buffer must be created UAV-capable before it can be cleared this way.
Solutions
- Recreate the buffer with BufferFlags.UnorderedAccess so a UAV view is allocated.
- Verify the buffer description includes the UAV flag before creating it in factory code.
- At the call site, guard with a null check on the buffer's UAV/UnorderedAccessView before clearing.
Example fix
// before var buffer = Buffer.NewStructured(device, elementCount, elementSize); commandList.ClearReadWrite(buffer, Vector4.Zero); // after var buffer = Buffer.NewStructured(device, elementCount, elementSize, BufferFlags.StructuredBuffer | BufferFlags.UnorderedAccess); commandList.ClearReadWrite(buffer, Vector4.Zero);
Defensive patterns
Strategy: validation
Validate before calling
if (buffer is null || buffer.NativeUnorderedAccessView.IsNull())
throw new InvalidOperationException("Buffer must be created with BufferFlags.UnorderedAccess");
commandList.ClearReadWrite(buffer, value); Type guard
static bool SupportsClearReadWrite(Buffer b) => b is not null && !b.NativeUnorderedAccessView.IsNull();
Try / catch
try { commandList.ClearReadWrite(buffer, Vector4.Zero); }
catch (ArgumentException ex) when (ex.ParamName == "buffer") { /* recreate buffer with UAV flag or use alternative init */ } Prevention
- Always include BufferFlags.UnorderedAccess when a buffer will be cleared or written by compute.
- Keep buffer factory helpers that encode required flags per usage.
- Assert UAV capability when the buffer is created, not at clear time.
When it happens
Trigger: Calling commandList.ClearReadWrite(buffer, new Vector4(...)) on a Buffer created without GraphicsResourceUsage/BufferFlags.UnorderedAccess (no UAV view allocated at creation).
Common situations: Forgetting BufferFlags.UnorderedAccess in Buffer.New; a buffer previously used only as a vertex/constant buffer being reused for compute output; copy-pasted clear code applied to a plain staging or structured buffer.
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
- Expecting a Texture supporting UAV
- Element size must be greater than zero for structured…
- Invalid shader stage
- Cannot clear a stencil buffer without a Stencil Buffer…
- Expecting a Buffer supporting UAV
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/8dbc5840154c4e2a.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs:952
scoped Span<float> colorFloats = color.AsSpan<Color4, float>(elementCount: 4);
nativeDeviceContext->ClearRenderTargetView(renderTarget.NativeRenderTargetView, ref colorFloats.GetReference());
}
/// <summary>
/// Clears a Read-Write Buffer.
/// </summary>
/// <param name="buffer">The Buffer to clear. It must have been created with read-write / unordered access flags.</param>
/// <param name="value">The value to use to clear the Buffer.</param>
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="buffer"/> must support Unordered Access.</exception>
public unsafe void ClearReadWrite(Buffer buffer, Vector4 value)
{
ArgumentNullException.ThrowIfNull(buffer);
RecordDebugCounter(DebugCounterKind.Clear);
if (buffer.NativeUnorderedAccessView.IsNull())
throw new ArgumentException("Expecting a Buffer supporting UAV", nameof(buffer));
nativeDeviceContext->ClearUnorderedAccessViewFloat(buffer.NativeUnorderedAccessView, (float*) &value);
}
/// <summary>
/// Clears a Read-Write Buffer.
/// </summary>
/// <param name="buffer">The Buffer to clear. It must have been created with read-write / unordered access flags.</param>
/// <param name="value">The value to use to clear the Buffer.</param>
/// <exception cref="ArgumentNullException"><paramref name="buffer"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="buffer"/> must support Unordered Access.</exception>
public unsafe void ClearReadWrite(Buffer buffer, Int4 value)
{
ArgumentNullException.ThrowIfNull(buffer);
RecordDebugCounter(DebugCounterKind.Clear);
if (buffer.NativeUnorderedAccessView.IsNull())
throw new ArgumentException("Expecting a Buffer supporting UAV", nameof(buffer));View on GitHub (pinned to 96fad776d2)