SubtitleEdit/subtitleedit · error · InvalidOperationException
No bitmaps to write.
Error message
No bitmaps to write.
What it means
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.
Source
Thrown at src/seconv/Core/ImageOutputWriter.cs:101
/// <summary>
/// Image-to-image variant: write a sequence of pre-rendered bitmaps (Blu-Ray .sup,
/// VobSub, MKV PGS, DVB-sub) into <paramref name="handler"/> without going through
/// <see cref="ImageRenderer"/>. Source dimensions baked into each
/// <see cref="BitmapSubtitleLoader.BitmapSubtitleItem"/> override
/// <see cref="ConversionOptions.Resolution"/> when present, so e.g. a 1920x1080
/// Blu-Ray sup re-exports as 1920x1080 BDN-XML even if the CLI's default
/// <c>--resolution</c> is something else.
/// </summary>
public static void WritePreservedBitmaps(
IReadOnlyList<BitmapSubtitleLoader.BitmapSubtitleItem> items,
string filePath,
IExportHandler handler,
ConversionOptions options)
{
if (items.Count == 0)
{
throw new InvalidOperationException("No bitmaps to write.");
}
var (defaultWidth, defaultHeight) = options.Resolution ?? (1920, 1080);
var first = items[0];
var firstParam = BuildPreservedParameter(first, 0, defaultWidth, defaultHeight, options);
handler.WriteHeader(filePath, firstParam);
for (var i = 0; i < items.Count; i++)
{
var item = items[i];
var ip = BuildPreservedParameter(item, i, defaultWidth, defaultHeight, options);
handler.CreateParagraph(ip);
handler.WriteParagraph(ip);
// We do NOT dispose item.Bitmap here — ownership stays with BitmapSubtitleItem;
// the caller disposes the whole list when done. Disposing twice would crash.
}
handler.WriteFooter();View on GitHub (pinned to 17a9f07487)
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.
Example fix
// before
ImageOutputWriter.WritePreservedBitmaps(items, outPath, handler, options);
// after
if (items.Count == 0)
return;
ImageOutputWriter.WritePreservedBitmaps(items, outPath, handler, options); Defensive patterns
Strategy: validation
Validate before calling
if (items == null || items.Count == 0)
{
Console.Error.WriteLine("No bitmap subtitle items to write.");
return;
} Type guard
static bool HasBitmapItems(IReadOnlyList<BitmapSubtitleLoader.BitmapSubtitleItem> items) => items != null && items.Count > 0;
Try / catch
try { ImageOutputWriter.WritePreservedBitmaps(items, outPath, handler, options); }
catch (InvalidOperationException ex) when (ex.Message.Contains("No bitmaps to write"))
{ /* report empty bitmap list to user */ } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- No paragraphs to render.
- Image-based formats require ConversionOptions
- No Blu-Ray sup subtitles found in: {filePath}
- No PGS subtitles in MKV track #{track.TrackNumber}.
- No VobSub subtitle packs in: {subPath}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/5e7165cfb5f13ebe.
Report an issue: GitHub.