{"record":{"id":"7ad9f750ca5a87fd","repo":"LorisYounger/VPet","slug":"decode-apng-frame-bitmap-failed","errorCode":null,"errorMessage":"Decode APNG frame bitmap failed.","messagePattern":"Decode APNG frame bitmap failed\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"VPet-Simulator.Core/Graph/APNGAnimation.cs","lineNumber":188,"sourceCode":"                FailMessage = $\"--APNGAnimation--{GraphInfo}--\\nPath: {Path}\\n{e.Message}\";\n            }\n        }\n\n        private void BuildSpriteSheet(ParsedApng parsed)\n        {\n            using var canvasBitmap = new SKBitmap(parsed.CanvasWidth, parsed.CanvasHeight, SKColorType.Bgra8888, SKAlphaType.Premul);\n            using var combinedBitmap = new SKBitmap(FrameWidth * parsed.Frames.Count, FrameHeight, SKColorType.Bgra8888, SKAlphaType.Premul);\n            using var combinedCanvas = new SKCanvas(combinedBitmap);\n            canvasBitmap.Erase(SKColors.Transparent);\n            combinedBitmap.Erase(SKColors.Transparent);\n\n            for (int i = 0; i < parsed.Frames.Count; i++)\n            {\n                var frameData = parsed.Frames[i];\n                using var previousCanvas = frameData.DisposeOp == 2 ? canvasBitmap.Copy() : null;\n                using var patchBitmap = DecodeFrameBitmap(parsed, frameData);\n                if (patchBitmap == null)\n                    throw new InvalidDataException(\"Decode APNG frame bitmap failed.\");\n\n                using (var canvas = new SKCanvas(canvasBitmap))\n                {\n                    if (frameData.BlendOp == 0)\n                    {\n                        using var clearPaint = new SKPaint { BlendMode = SKBlendMode.Src, Color = SKColors.Transparent };\n                        canvas.DrawRect(new SKRect(frameData.XOffset, frameData.YOffset, frameData.XOffset + frameData.Width, frameData.YOffset + frameData.Height), clearPaint);\n                    }\n                    canvas.DrawBitmap(patchBitmap, frameData.XOffset, frameData.YOffset);\n                }\n\n                SKBitmap drawBitmap = canvasBitmap;\n                SKBitmap? scaledBitmap = null;\n                if (canvasBitmap.Width != FrameWidth || canvasBitmap.Height != FrameHeight)\n                {\n                    scaledBitmap = new SKBitmap(FrameWidth, FrameHeight, canvasBitmap.ColorType, canvasBitmap.AlphaType);\n                    canvasBitmap.ScalePixels(scaledBitmap, SKSamplingOptions.Default);\n                    drawBitmap = scaledBitmap;","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/LorisYounger/VPet/blob/ffb9cc2a856244a0f91aa5ecf10d097bcdd4954f/VPet-Simulator.Core/Graph/APNGAnimation.cs#L170-L206","documentation":"During sprite-sheet assembly, DecodeFrameBitmap failed to decode a frame's compressed image data (IDAT/fdAT payload) into an SkiaSharp bitmap, returning null. The loader throws InvalidDataException rather than compositing a corrupt frame.","triggerScenarios":"BuildSpriteSheet iterates parsed frames and DecodeFrameBitmap returns null for a frame whose zlib/image data is corrupt, truncated, or uses unsupported color formats.","commonSituations":"Partially downloaded animation files; corrupted fdAT chunks from bad hex edits; APNG variants whose frame data SkiaSharp cannot decode; assets damaged by transfer in text/FTP ASCII mode.","solutions":["Re-download or re-export the APNG from a known-good source.","Validate each frame's data decodes (e.g. SKBitmap.Decode) before shipping the asset.","Update SkiaSharp to a version supporting the file's color/interlace format.","Regenerate the animation with apngasm/ffmpeg to rebuild frame chunks."],"exampleFix":"// before\n// asset shipped with truncated fdAT; crash at BuildSpriteSheet\n// after\n// rebuild:\n// apngasm -o fixed.png frames/*.png\nnew APNGAnimation(\"fixed.png\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { var anim = new APNGAnimation(path); } catch (InvalidDataException ex) when (ex.Message.Contains(\"Decode\")) { Log.Error($\"corrupt frame data in {path}\"); LoadFallbackGraph(); }","preventionTips":["Verify assets with checksums after download","Always transfer assets in binary mode","Test-decode all frames with SkiaSharp in asset CI"],"tags":["png","decoding","skia"],"backgroundTag":"file-read-failed","analyzedSha":"ffb9cc2a856244a0f91aa5ecf10d097bcdd4954f","analyzedAt":"2026-09-15T21:21:10.398Z","contentChangedAt":"2026-09-15T21:21:10.398Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}