{"record":{"id":"5e7165cfb5f13ebe","repo":"SubtitleEdit/subtitleedit","slug":"no-bitmaps-to-write","errorCode":null,"errorMessage":"No bitmaps to write.","messagePattern":"No bitmaps to write\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/ImageOutputWriter.cs","lineNumber":101,"sourceCode":"\n    /// <summary>\n    /// Image-to-image variant: write a sequence of pre-rendered bitmaps (Blu-Ray .sup,\n    /// VobSub, MKV PGS, DVB-sub) into <paramref name=\"handler\"/> without going through\n    /// <see cref=\"ImageRenderer\"/>. Source dimensions baked into each\n    /// <see cref=\"BitmapSubtitleLoader.BitmapSubtitleItem\"/> override\n    /// <see cref=\"ConversionOptions.Resolution\"/> when present, so e.g. a 1920x1080\n    /// Blu-Ray sup re-exports as 1920x1080 BDN-XML even if the CLI's default\n    /// <c>--resolution</c> is something else.\n    /// </summary>\n    public static void WritePreservedBitmaps(\n        IReadOnlyList<BitmapSubtitleLoader.BitmapSubtitleItem> items,\n        string filePath,\n        IExportHandler handler,\n        ConversionOptions options)\n    {\n        if (items.Count == 0)\n        {\n            throw new InvalidOperationException(\"No bitmaps to write.\");\n        }\n\n        var (defaultWidth, defaultHeight) = options.Resolution ?? (1920, 1080);\n\n        var first = items[0];\n        var firstParam = BuildPreservedParameter(first, 0, defaultWidth, defaultHeight, options);\n        handler.WriteHeader(filePath, firstParam);\n\n        for (var i = 0; i < items.Count; i++)\n        {\n            var item = items[i];\n            var ip = BuildPreservedParameter(item, i, defaultWidth, defaultHeight, options);\n            handler.CreateParagraph(ip);\n            handler.WriteParagraph(ip);\n            // We do NOT dispose item.Bitmap here — ownership stays with BitmapSubtitleItem;\n            // the caller disposes the whole list when done. Disposing twice would crash.\n        }\n        handler.WriteFooter();","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/ImageOutputWriter.cs#L83-L119","documentation":"Thrown by ImageOutputWriter.WritePreservedBitmaps when the list of bitmap subtitle items is empty. This method re-exports already-bitmapped subtitle formats (e.g. re-encoding a Blu-ray sup or BDN-XML) — it needs at least one bitmap item to write a header and body. Zero items means there is nothing to preserve.","triggerScenarios":"Calling WritePreservedBitmaps(items, filePath, handler, options) where items.Count == 0. Occurs when a bitmap subtitle source loaded zero items (e.g. a .sup/.xml file whose entries all failed parsing), or when an upstream filter produced an empty item list.","commonSituations":"Re-exporting a corrupt or empty Blu-ray sup / BDN-XML file whose bitmap entries were all rejected by the loader; a deserialized bitmap list that was cleared or never populated before the export call.","solutions":["Check items.Count > 0 before calling WritePreservedBitmaps and report to the user.","Investigate the BitmapSubtitleLoader step — if the source should contain bitmap items, verify the loader's parse path and warning output.","Skip the export when the source is legitimately empty."],"exampleFix":"// before\nImageOutputWriter.WritePreservedBitmaps(items, outPath, handler, options);\n\n// after\nif (items.Count == 0)\n    return;\nImageOutputWriter.WritePreservedBitmaps(items, outPath, handler, options);","handlingStrategy":"validation","validationCode":"if (items == null || items.Count == 0)\n{\n    Console.Error.WriteLine(\"No bitmap subtitle items to write.\");\n    return;\n}","typeGuard":"static bool HasBitmapItems(IReadOnlyList<BitmapSubtitleLoader.BitmapSubtitleItem> items) => items != null && items.Count > 0;","tryCatchPattern":"try { ImageOutputWriter.WritePreservedBitmaps(items, outPath, handler, options); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"No bitmaps to write\"))\n{ /* report empty bitmap list to user */ }","preventionTips":["Check items.Count after loading a bitmap subtitle source (sup/BDN-XML) before re-exporting.","Log loader warnings — bitmap items that fail to parse are reported there before the export step.","Gate the WritePreservedBitmaps call behind a non-empty-items check."],"tags":["image-export","bitmap","empty-input","validation","subtitles"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}