{"record":{"id":"9c46cbad8f9f616a","repo":"stride3d/stride","slug":"invalid-destination-pixelbufferarray-must-have-the-same","errorCode":null,"errorMessage":"Invalid destination pixelBufferArray. Must have the same Width, Height and Format.","messagePattern":"Invalid destination pixelBufferArray\\. Must have the same Width, Height and Format\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Foundation/Graphics/PixelBuffer.cs","lineNumber":147,"sourceCode":"        /// <value>The pointer to the pixel buffer.</value>\n        public IntPtr DataPointer { get { return this.dataPointer; } }\n\n        /// <summary>\n        /// Copies this pixel buffer to a destination pixel buffer.\n        /// </summary>\n        /// <param name=\"pixelBuffer\">The destination pixel buffer.</param>\n        /// <remarks>\n        /// The destination pixel buffer must have exactly the same dimensions (width, height) and format than this instance.\n        /// Destination buffer can have different row stride.\n        /// </remarks>\n        public unsafe void CopyTo(PixelBuffer pixelBuffer)\n        {\n            // Check that buffers are identical\n            if (this.Width != pixelBuffer.Width\n                || this.Height != pixelBuffer.Height\n                || this.Format != pixelBuffer.Format)\n            {\n                throw new ArgumentException(\"Invalid destination pixelBufferArray. Must have the same Width, Height and Format.\", \"pixelBuffer\");\n            }\n\n            // If buffers have same size, than we can copy it directly\n            if (this.BufferStride == pixelBuffer.BufferStride)\n            {\n                MemoryUtilities.CopyWithAlignmentFallback((void*)pixelBuffer.DataPointer, source: (void*)DataPointer, (uint)BufferStride);\n            }\n            else\n            {\n                var srcPointer = (byte*)this.DataPointer;\n                var dstPointer = (byte*)pixelBuffer.DataPointer;\n                var rowStride = Math.Min(RowStride, pixelBuffer.RowStride);\n\n                // Copy per scanline\n                for (int i = 0; i < Height; i++)\n                {\n                    MemoryUtilities.CopyWithAlignmentFallback(dstPointer, srcPointer, (uint)rowStride);\n                    srcPointer += this.RowStride;","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Foundation/Graphics/PixelBuffer.cs#L129-L165","documentation":"PixelBuffer.CopyTo only supports copying between buffers with identical Width, Height, and PixelFormat; it is a raw memory copy, not a rescaling or format-conversion routine. When the destination's dimensions or format differ, it throws ArgumentException for the pixelBuffer argument.","triggerScenarios":"Calling sourcePixelBuffer.CopyTo(dest) where dest.Width/Height/Format differs from the source — e.g. copying an R8G8B8A8_UNorm buffer into an sRGB-format buffer, or copying into a mip level of different dimensions.","commonSituations":"See trigger scenarios.","solutions":["Ensure destination and source have the same Width, Height, and Format before copying (check pixelBuffer.Width/Height/Format).","Use format-conversion APIs instead of CopyTo when the pixel formats differ.","Create the destination buffer via an Image/PixelData factory that matches the source description."],"exampleFix":"// before\nsrcBuffer.CopyTo(destBuffer);\n// after\nif (destBuffer.Format != srcBuffer.Format || destBuffer.Width != srcBuffer.Width || destBuffer.Height != srcBuffer.Height)\n    destBuffer = new Image(srcBuffer.Format, srcBuffer.Width, srcBuffer.Height).GetPixelBuffer();\nsrcBuffer.CopyTo(destBuffer);","handlingStrategy":"validation","validationCode":"bool CanCopy(PixelBuffer src, PixelBuffer dst) =>\n    src.Width == dst.Width && src.Height == dst.Height && src.Format == dst.Format;","typeGuard":null,"tryCatchPattern":"try { src.CopyTo(dst); }\ncatch (ArgumentException ex) when (ex.ParamName == \"pixelBuffer\") { dst = RecreateMatchingBuffer(src); src.CopyTo(dst); }","preventionTips":["Create destination buffers from the source's ImageDescription so dimensions/format always match.","Never rely on CopyTo for format conversion; use explicit conversion helpers.","Assert equality of Width/Height/Format in debug builds at buffer creation sites."],"tags":["graphics","pixel-buffer","format-mismatch","copy"],"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"}