tui-cs/Terminal.Gui · error · InvalidOperationException
No raster graphics support available.
Error message
No raster graphics support available.
What it means
Thrown by ImageView.ViewportToScreenInPixels when GetActiveResolution() returns null, meaning the terminal/driver provides no raster graphics pixel resolution (neither Kitty nor Sixel cell-pixel dimensions are available). The method exists to compute screen pixel coordinates for raster drawing, so without a resolution there is no meaningful result and it fails fast rather than returning a garbage rectangle.
Source
Thrown at Terminal.Gui/Views/ImageView/ImageView.cs:328
/// Gets whether the current rendering mode is using sixel.
/// </summary>
[Obsolete ("Use IsUsingRasterGraphics instead. IsUsingSixel will be removed in a future version.")]
public bool IsUsingSixel => UseRasterGraphics && !IsKittyGraphicsActive () && App?.Driver?.SixelSupport is { IsSupported: true };
/// <summary>
/// Converts the Viewport to screen coordinates in pixels.
/// </summary>
/// <remarks>
/// <para>
/// This method accounts for the terminal's cell resolution and the viewport's
/// size, returning the exact pixel dimensions and position required for
/// fully cover the viewport.
/// </para>
/// </remarks>
/// <returns>The screen coordinates of the Viewport in pixels.</returns>
public Rectangle ViewportToScreenInPixels ()
{
Size resolution = GetActiveResolution () ?? throw new InvalidOperationException (@"No raster graphics support available.");
int pixelsPerCellX = resolution.Width;
int pixelsPerCellY = resolution.Height;
Rectangle boundsRect = ViewportToScreen ();
int targetWidthInPixels = boundsRect.Width * pixelsPerCellX;
int targetHeightInPixels = IsKittyGraphicsActive ()
? boundsRect.Height * pixelsPerCellY
: SixelEncoder?.GetHeightInPixels (boundsRect.Height, pixelsPerCellY) ?? boundsRect.Height * pixelsPerCellY;
return new Rectangle (boundsRect.X * pixelsPerCellX, boundsRect.Y * pixelsPerCellY, targetWidthInPixels, targetHeightInPixels);
}
/// <summary>
/// Returns the resolution (pixels per cell) for the active raster graphics protocol,
/// preferring Kitty over Sixel. Returns <see langword="null"/> when neither is available.
/// </summary>
private Size? GetActiveResolution ()View on GitHub (pinned to 2e47b11478)
Solutions
- Gate the call on IsUsingRasterGraphics (or check App?.Driver?.SixelSupport?.IsSupported) before invoking ViewportToScreenInPixels.
- Avoid calling this method for character-cell rendering paths; it is only meaningful when raster output is active.
- If you must compute pixel rects defensively, fall back to cell-based math (Viewport width/height in cells) when raster is unavailable.
Example fix
// before
Rectangle px = imageView.ViewportToScreenInPixels(); // throws 164
// after
Rectangle px = imageView.IsUsingRasterGraphics
? imageView.ViewportToScreenInPixels()
: imageView.Viewport; Defensive patterns
Strategy: type-guard
Validate before calling
Rectangle px = imageView.IsUsingRasterGraphics
? imageView.ViewportToScreenInPixels()
: imageView.Viewport; Type guard
static bool HasRasterSupport(ImageView v) => v.IsUsingRasterGraphics;
Prevention
- Only call ViewportToScreenInPixels when raster graphics are active.
- Gate on App?.Driver?.SixelSupport?.IsSupported in lower-level code.
- Avoid the method in CI/headless unless the driver reports raster support.
When it happens
Trigger: Calling ViewportToScreenInPixels() on a driver/terminal that does not report raster graphics support, or calling it before the ImageView has determined its active raster mode (e.g. before first render or when UseRasterGraphics is false).
Common situations: Running under a plain ANSI/Curses driver or a terminal without sixel/Kitty; calling during design/preview mode; running in CI with a null/fake driver that omits SixelSupport.
Related errors
- Zoom level must be a finite number.
- Maximum sixel palette colors must be greater than zero.
- Failed to copy from the OS clipboard.
- Failed to paste to the OS clipboard.
- Process timed out. Command line: {process.StartInfo.FileName
AI-assisted analysis of tui-cs/Terminal.Gui@2e47b11478 (2026-08-13).
Data as JSON: /api/errors/ec01e4ba2ca6cad1.
Report an issue: GitHub.