{"record":{"id":"1f4425c627f683f9","repo":"MonoGame/MonoGame","slug":"unexpected-intermediate-format-intermediateforma","errorCode":null,"errorMessage":"Unexpected intermediate format: {intermediateFormat}","messagePattern":"Unexpected intermediate format: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"MonoGame.Framework.Content.Pipeline/Graphics/GraphicsUtil.cs","lineNumber":81,"sourceCode":"                {\n                    var errorMsg = Marshal.PtrToStringUTF8(err);\n                    throw new InvalidContentException($\"Bitmap resize failed: {errorMsg}\");\n                }\n            }\n            finally\n            {\n                if (srcHandle.IsAllocated)\n                    srcHandle.Free();\n                if (dstHandle.IsAllocated)\n                    dstHandle.Free();\n            }\n\n            src = intermediateFormat switch\n            {\n                SurfaceFormat.Color => new PixelBitmapContent<Color>(newWidth, newHeight),\n                SurfaceFormat.Rgba64 => new PixelBitmapContent<Rgba64>(newWidth, newHeight),\n                SurfaceFormat.Vector4 => new PixelBitmapContent<Vector4>(newWidth, newHeight),\n                _ => throw new InvalidOperationException($\"Unexpected intermediate format: {intermediateFormat}\"),\n            };\n            src.SetPixelData(newBytes);\n\n            // Convert back to source type if required\n            if (format != intermediateFormat)\n            {\n                var s = (T)Activator.CreateInstance(bitmap.GetType(), [newWidth, newHeight])!;\n                BitmapContent.Copy(src, s);\n                src = s;\n            }\n\n            if (src is not T ret)\n            {\n                throw new Exception($\"Invalid return type for bitmap, expected {typeof(T)}, got {src}\");\n            }\n\n            return ret;\n        }","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/MonoGame/MonoGame/blob/1d71bbd0ff4071a03caa583aa3bc56b85924a819/MonoGame.Framework.Content.Pipeline/Graphics/GraphicsUtil.cs#L63-L99","documentation":"Thrown by GraphicsUtil's bitmap resize routine when the intermediate SurfaceFormat used for the resize does not match one of the three supported formats (Color, Rgba64, Vector4). The switch expression's default arm raises this InvalidOperationException with the offending format.","triggerScenarios":"The bitmap being resized reports an intermediate format outside {SurfaceFormat.Color, SurfaceFormat.Rgba64, SurfaceFormat.Vector4}. This intermediate format is derived from the source bitmap type during the resize pipeline.","commonSituations":"Passing a compressed (DXT/BCx/PVRTC/ETC) or exotic (HalfVector4, NormalizedByte4, etc.) bitmap content directly into the resize utility without first decompressing/converting it; a custom BitmapContent subclass returning an unexpected SurfaceFormat.","solutions":["Convert the bitmap to an uncompressed PixelBitmapContent<Color> before resizing.","Ensure the source TextureContent face is a supported uncompressed format.","Extend the switch (if you control the codebase) to handle the additional intermediate format."],"exampleFix":"// before\nGraphicsUtil.Resize(compressedTextureFace, newWidth, newHeight);\n\n// after\ncontent.ConvertBitmapType(typeof(PixelBitmapContent<Color>));\nGraphicsUtil.Resize(content.Faces[0][0], newWidth, newHeight);","handlingStrategy":"validation","validationCode":"var allowed = new[] { SurfaceFormat.Color, SurfaceFormat.Rgba64, SurfaceFormat.Vector4 };\nvar fmt = bitmap is BitmapContent bc ? /* resolve format */ SurfaceFormat.Color : throw new InvalidOperationException();\nif (!allowed.Contains(fmt))\n    throw new InvalidOperationException($\"Convert bitmap to an uncompressed Color/Rgba64/Vector4 format before resizing; got {fmt}.\");","typeGuard":"static bool IsResizableFormat(BitmapContent bitmap) =>\n    bitmap is PixelBitmapContent<Color>\n        or PixelBitmapContent<Rgba64>\n        or PixelBitmapContent<Vector4>;","tryCatchPattern":"try { GraphicsUtil.Resize(bitmap, newWidth, newHeight); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unexpected intermediate format\"))\n{\n    content.ConvertBitmapType(typeof(PixelBitmapContent<Color>));\n    GraphicsUtil.Resize(content.Faces[0][0], newWidth, newHeight);\n}","preventionTips":["Decompress textures to PixelBitmapContent<Color> before any resize step.","Avoid routing cube maps, DXT/BCx, or PVRTC content through the resize utility directly.","Centralize a 'prepare for resize' helper that enforces supported formats."],"tags":["bitmap","surface-format","resize","content-pipeline"],"backgroundTag":null,"analyzedSha":"1d71bbd0ff4071a03caa583aa3bc56b85924a819","analyzedAt":"2026-08-13T17:10:33.625Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}