{"record":{"id":"16e6fa119c101c8f","repo":"stride3d/stride","slug":"offsets-are-only-supported-for-textures-declared-with-nameof","errorCode":null,"errorMessage":"Offsets are only supported for Textures declared with {nameof(GraphicsResourceUsage)}.{nameof(GraphicsResourceUsage.Default)}","messagePattern":"Offsets are only supported for Textures declared with (.+?)\\.(.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Buffer.cs","lineNumber":514,"sourceCode":"\n            // If the Buffer is declared as Default usage, we can only use UpdateSubresource, which is not optimal but better than nothing\n            if (Description.Usage == GraphicsResourceUsage.Default)\n            {\n                // Set up the dest region inside the Buffer\n                if (Description.BufferFlags.HasFlag(BufferFlags.ConstantBuffer))\n                {\n                    commandList.UpdateSubResource(this, subResourceIndex: 0, fromDataAsBytes);\n                }\n                else\n                {\n                    var destRegion = new ResourceRegion(left: offsetInBytes, top: 0, front: 0, right: offsetInBytes + fromDataSizeInBytes, bottom: 1, back: 1);\n                    commandList.UpdateSubResource(this, subResourceIndex: 0, fromDataAsBytes, destRegion);\n                }\n            }\n            else\n            {\n                if (offsetInBytes > 0)\n                    throw new ArgumentException(\"Offsets are only supported for Textures declared with {nameof(GraphicsResourceUsage)}.{nameof(GraphicsResourceUsage.Default)}\", nameof(offsetInBytes));\n\n                // Map the Buffer to CPU-writable memory\n                var mappedResource = commandList.MapSubResource(this, subResourceIndex: 0, Usage == GraphicsResourceUsage.Staging ? MapMode.Write : MapMode.WriteDiscard);\n                var toData = new Span<TData>((void*) mappedResource.DataBox.DataPointer, fromData.Length);\n                fromData.CopyTo(toData);\n                //Utilities.CopyWithAlignmentFallback((void*)mappedResource.DataBox.DataPointer, pointer, (uint)sizeInBytes);\n                commandList.UnmapSubResource(mappedResource);\n            }\n        }\n\n        #endregion\n\n        /// <summary>\n        ///   Creates a new <see cref=\"Buffer\"/>.\n        /// </summary>\n        /// <param name=\"device\">The <see cref=\"GraphicsDevice\"/>.</param>\n        /// <param name=\"description\">The description of the Buffer.</param>\n        /// <param name=\"viewFormat\">","sourceCodeStart":496,"sourceCodeEnd":532,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Buffer.cs#L496-L532","documentation":"SetData supports a byte offset only when the buffer's usage is GraphicsResourceUsage.Default, because then it uses UpdateSubresource with a destination region. For other usages (Dynamic/Staging) the CPU-map path has no subresource region support, so any offsetInBytes > 0 throws ArgumentException. The message text literally leaks the {nameof(...)} placeholders unexpanded.","triggerScenarios":"Calling buffer.SetData(commandList, data, offsetInBytes: N) with N > 0 on a buffer whose Description.Usage is Dynamic or Staging (e.g. a Dynamic constant or vertex buffer).","commonSituations":"Partially updating sub-ranges of a dynamic buffer with an offset; porting XNA/MonoGame code that used UpdateSubresource offsets onto a Staging or Dynamic buffer.","solutions":["Use GraphicsResourceUsage.Default for the buffer when you need offset writes.","Set offsetInBytes to 0 and upload the full data instead of a partial offset write.","For partial updates of dynamic buffers, write the whole slab and use a constant-buffer offset in the shader, or create the buffer with Default usage."],"exampleFix":"// before\ndynamicBuffer.SetData(cmd, newData, offsetInBytes: 64); // throws\n// after\ndefaultBuffer = Buffer.New<float>(device, count, BufferFlags.ConstantBuffer, GraphicsResourceUsage.Default);\ndefaultBuffer.SetData(cmd, newData, offsetInBytes: 64);","handlingStrategy":"validation","validationCode":"if (offsetInBytes > 0 && buffer.Description.Usage != GraphicsResourceUsage.Default)\n    throw new InvalidOperationException(\"Offset writes need Default usage\");","typeGuard":"bool SupportsOffsetWrite(Buffer b) => b.Description.Usage == GraphicsResourceUsage.Default;","tryCatchPattern":"try { buffer.SetData(cmd, data, offsetInBytes); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Offsets are only supported\"))\n{\n    buffer.SetData(cmd, data, 0); // fall back to full write\n}","preventionTips":["Use Default usage for offset writes.","Default offsetInBytes to 0 for Dynamic/Staging buffers.","Prefer writing whole slabs for dynamic buffers."],"tags":["graphics","buffer","argument-validation","usage"],"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"}