{"record":{"id":"8dbc5840154c4e2a","repo":"stride3d/stride","slug":"expecting-a-buffer-supporting-uav","errorCode":null,"errorMessage":"Expecting a Buffer supporting UAV","messagePattern":"Expecting a Buffer supporting UAV","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs","lineNumber":952,"sourceCode":"\n            scoped Span<float> colorFloats = color.AsSpan<Color4, float>(elementCount: 4);\n            nativeDeviceContext->ClearRenderTargetView(renderTarget.NativeRenderTargetView, ref colorFloats.GetReference());\n        }\n\n        /// <summary>\n        ///   Clears a Read-Write Buffer.\n        /// </summary>\n        /// <param name=\"buffer\">The Buffer to clear. It must have been created with read-write / unordered access flags.</param>\n        /// <param name=\"value\">The value to use to clear the Buffer.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"buffer\"/> is <see langword=\"null\"/>.</exception>\n        /// <exception cref=\"ArgumentException\"><paramref name=\"buffer\"/> must support Unordered Access.</exception>\n        public unsafe void ClearReadWrite(Buffer buffer, Vector4 value)\n        {\n            ArgumentNullException.ThrowIfNull(buffer);\n            RecordDebugCounter(DebugCounterKind.Clear);\n\n            if (buffer.NativeUnorderedAccessView.IsNull())\n                throw new ArgumentException(\"Expecting a Buffer supporting UAV\", nameof(buffer));\n\n            nativeDeviceContext->ClearUnorderedAccessViewFloat(buffer.NativeUnorderedAccessView, (float*) &value);\n        }\n\n        /// <summary>\n        ///   Clears a Read-Write Buffer.\n        /// </summary>\n        /// <param name=\"buffer\">The Buffer to clear. It must have been created with read-write / unordered access flags.</param>\n        /// <param name=\"value\">The value to use to clear the Buffer.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"buffer\"/> is <see langword=\"null\"/>.</exception>\n        /// <exception cref=\"ArgumentException\"><paramref name=\"buffer\"/> must support Unordered Access.</exception>\n        public unsafe void ClearReadWrite(Buffer buffer, Int4 value)\n        {\n            ArgumentNullException.ThrowIfNull(buffer);\n            RecordDebugCounter(DebugCounterKind.Clear);\n\n            if (buffer.NativeUnorderedAccessView.IsNull())\n                throw new ArgumentException(\"Expecting a Buffer supporting UAV\", nameof(buffer));","sourceCodeStart":934,"sourceCodeEnd":970,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs#L934-L970","documentation":"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.","triggerScenarios":"Calling commandList.ClearReadWrite(buffer, new Vector4(...)) on a Buffer created without GraphicsResourceUsage/BufferFlags.UnorderedAccess (no UAV view allocated at creation).","commonSituations":"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.","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."],"exampleFix":"// before\nvar buffer = Buffer.NewStructured(device, elementCount, elementSize);\ncommandList.ClearReadWrite(buffer, Vector4.Zero);\n// after\nvar buffer = Buffer.NewStructured(device, elementCount, elementSize, BufferFlags.StructuredBuffer | BufferFlags.UnorderedAccess);\ncommandList.ClearReadWrite(buffer, Vector4.Zero);","handlingStrategy":"validation","validationCode":"if (buffer is null || buffer.NativeUnorderedAccessView.IsNull())\n    throw new InvalidOperationException(\"Buffer must be created with BufferFlags.UnorderedAccess\");\ncommandList.ClearReadWrite(buffer, value);","typeGuard":"static bool SupportsClearReadWrite(Buffer b) => b is not null && !b.NativeUnorderedAccessView.IsNull();","tryCatchPattern":"try { commandList.ClearReadWrite(buffer, Vector4.Zero); }\ncatch (ArgumentException ex) when (ex.ParamName == \"buffer\") { /* recreate buffer with UAV flag or use alternative init */ }","preventionTips":["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."],"tags":["direct3d11","graphics","uav","buffer","clear"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}