invoke-ai/InvokeAI · error · ValueError

Source dimensions must be positive.

Error message

Source dimensions must be positive.

What it means

The Wan ideal-dimensions helper computes a scaled/snapped output size from a source image, and requires positive width and height. A zero or negative dimension would break the aspect-ratio math (division by zero or non-positive scaling), so it fails fast with this ValueError.

Source

Thrown at invokeai/app/invocations/wan_ideal_dimensions.py:62

}


def _scale_and_snap(
    width: int,
    height: int,
    target_short_side: int,
    rounding: WanRounding,
    multiple: int,
) -> tuple[int, int]:
    """Scale a source W×H so its shorter side equals ``target_short_side``, then
    snap each dimension to ``multiple`` using the requested rounding mode.

    ``multiple`` is the Wan pixel-grid constraint (16 for the 8x-VAE I2V/T2V
    models, 32 for the 16x-VAE TI2V-5B). Shared by both ideal-dimensions nodes.
    """
    short = min(width, height)
    if short <= 0:
        raise ValueError("Source dimensions must be positive.")

    # Reject sources so narrow that the scaled long side is still under one Wan
    # pixel grid. The downstream clamp to ``max(w, multiple)`` would otherwise
    # silently return multiple×multiple, which has no relation to the requested
    # aspect ratio — better to fail fast and have the workflow author fix inputs.
    long_side = max(width, height)
    if long_side < multiple:
        raise ValueError(
            f"Source longer side ({long_side}px) is smaller than the Wan pixel grid ({multiple}px). "
            f"Use an input image at least {multiple}px on its longer side."
        )

    scale = target_short_side / short
    raw_w = width * scale
    raw_h = height * scale

    if rounding == "floor":
        w = int(raw_w // multiple) * multiple

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Provide a valid source image with positive width and height
  2. Fix the width/height input values on the ideal-dimensions node (must be > 0)
  3. Check the upstream node producing dimensions for a failed/empty metadata read

Example fix

// before
idealDims: width=0, height=1080
// after
idealDims: width=1920, height=1080
Defensive patterns

Strategy: validation

Validate before calling

if width <= 0 or height <= 0:
    raise ValueError(f"invalid source dimensions {width}x{height}")

Type guard

def has_valid_dimensions(img) -> bool:
    return img.width > 0 and img.height > 0

Try / catch

try:
    dims = ideal_dims.invoke(context)
except ValueError as e:
    if 'dimensions must be positive' in str(e):
        fix_or_reload_source_image()
    else:
        raise

Prevention

When it happens

Trigger: Passing width=0, height=0, or negative values into a Wan Ideal Dimensions node's width/height inputs; upstream nodes emitting empty/invalid dimensions (e.g., an image metadata read that returned 0).

Common situations: Wired-from-metadata workflows where the source image has no stored dimensions; typos or invalid workflow JSON with 0-valued dimension fields.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/bad8434ae1ad859c. Report an issue: GitHub.