{"record":{"id":"4d239119bff95237","repo":"MonoGame/MonoGame","slug":"etc1-bitmap-with-width-width-and-height-height","errorCode":null,"errorMessage":"ETC1 bitmap with width {Width} and height {Height} needs {bytesRequired} bytes. Received {sourceData?.Length ?? 0} bytes","messagePattern":"ETC1 bitmap with width (.+?) and height (.+?) needs (.+?) bytes\\. Received (.+?) bytes","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework.Content.Pipeline/Graphics/Etc1BitmapContent.cs","lineNumber":42,"sourceCode":"        /// <summary>\n        /// Initializes a new instance of Etc1BitmapContent with the specified width or height.\n        /// </summary>\n        /// <param name=\"width\">Width in pixels of the bitmap resource.</param>\n        /// <param name=\"height\">Height in pixels of the bitmap resource.</param>\n        public Etc1BitmapContent(int width, int height) : base(width, height)\n        {\n        }\n\n        /// <inheritdoc/>\n        public override byte[] GetPixelData() => _data;\n\n        /// <inheritdoc/>\n        public override void SetPixelData(byte[]? sourceData)\n        {\n            var bytesRequired = ((Width + 3) >> 2) * ((Height + 3) >> 2) * SurfaceFormat.RgbEtc1.GetSize();\n            if (bytesRequired != (sourceData?.Length ?? 0))\n            {\n                throw new ArgumentException($\"ETC1 bitmap with width {Width} and height {Height} needs {bytesRequired} bytes. Received {sourceData?.Length ?? 0} bytes\");\n            }\n\n            if (sourceData == null || sourceData.Length == 0)\n            {\n                _data = [];\n                return;\n            }\n\n            if (_data == null || _data.Length != bytesRequired)\n            {\n                _data = new byte[bytesRequired];\n            }\n\n            Buffer.BlockCopy(sourceData, 0, _data, 0, bytesRequired);\n        }\n\n        /// <inheritdoc/>\n        protected override bool TryCopyFrom(BitmapContent sourceBitmap, Rectangle sourceRegion, Rectangle destinationRegion)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework.Content.Pipeline/Graphics/Etc1BitmapContent.cs#L24-L60","documentation":"Etc1BitmapContent.SetPixelData validates that the supplied byte buffer exactly matches the ETC1 footprint: ((Width+3)>>2)*((Height+3)>>2) blocks times the RgbEtc1 block size (8 bytes per 4x4 block, padded up). A mismatch means the data cannot be a valid ETC1 encoding of a bitmap this size, so it rejects the write with the expected vs received sizes.","triggerScenarios":"Calling SetPixelData with a buffer whose length is not the exact ETC1 block-padded byte count for the bitmap's Width/Height; e.g. feeding raw RGBA, feeding DXT/ETC2 bytes, or wrong width/height on the bitmap.","commonSituations":"Mismatched source texture dimensions vs. the Etc1BitmapContent dimensions; passing uncompressed pixel data to a compressed bitmap; off-by-block-padding errors in a custom ETC encoder output.","solutions":["Allocate the Etc1BitmapContent with the same width/height as the source texture.","Pre-compute bytesRequired = ((W+3)>>2)*((H+3)>>2)*SurfaceFormat.RgbEtc1.GetSize() and supply exactly that many bytes.","Ensure you pass the ETC1-encoded block data, not raw RGBA."],"exampleFix":"// before\netc1.SetPixelData(rawRgbaBytes); // wrong size\n// after\nint need = ((W+3)>>2) * ((H+3)>>2) * SurfaceFormat.RgbEtc1.GetSize();\nbyte[] encoded = Etc1Encoder.Encode(rawRgbaBytes, W, H);\nDebug.Assert(encoded.Length == need);\netc1.SetPixelData(encoded);","handlingStrategy":"validation","validationCode":"int need = ((etc1.Width + 3) >> 2) * ((etc1.Height + 3) >> 2) * SurfaceFormat.RgbEtc1.GetSize();\nif ((data?.Length ?? 0) != need)\n    throw new ArgumentException($\"Expected {need} ETC1 bytes, got {data?.Length ?? 0}.\");\netc1.SetPixelData(data);","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Match bitmap dimensions to the source texture.","Pass ETC1-encoded block data, never raw RGBA."],"tags":["content-pipeline","bitmap","etc1","compression","argument"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}