Comfy-Org/ComfyUI · error · ValueError

normalized element boxes need canvas_width and canvas_height

Error message

normalized element boxes need canvas_width and canvas_height to resolve to pixels

What it means

Element-style boxes (dicts with a normalized 'bbox' key) are stored in 0-1 normalized coordinates and must be multiplied by canvas_width/canvas_height to become pixels. If any element is detected in the input but either canvas dimension is <= 0 (unset, zero, or negative), resolution is impossible and the node raises this instead of producing boxes at nonsense coordinates.

Source

Thrown at comfy_extras/nodes_compositor.py:82

    if bboxes is None:
        return []
    if isinstance(bboxes, str):
        text = bboxes.strip()
        if not text:
            return []
        try:
            bboxes = json.loads(text)
        except (json.JSONDecodeError, ValueError) as exc:
            raise ValueError(f"bboxes string input is not valid JSON: {exc}") from exc
    probe = bboxes if isinstance(bboxes, list) else [bboxes]
    if probe and isinstance(probe[0], list):
        probe = probe[0]
    has_elements = any(
        isinstance(box, dict) and isinstance(box.get("bbox"), (list, tuple))
        for box in probe
    )
    if has_elements and (canvas_width <= 0 or canvas_height <= 0):
        raise ValueError(
            "normalized element boxes need canvas_width and canvas_height to resolve to pixels"
        )
    return boxes_from_input(bboxes, canvas_width, canvas_height)


def _item_mask_frame(mask, index: int) -> torch.Tensor | None:
    if not isinstance(mask, torch.Tensor):
        return None
    if mask.shape[0] == 1:
        return mask[:1]
    if index < mask.shape[0]:
        return mask[index : index + 1]
    return None


def expand_item_frames(items: list[dict]) -> list[dict]:
    frames = []
    for item in items:

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Connect or set canvas_width and canvas_height to positive values matching the target composite (typically the base image's dimensions).
  2. Convert normalized element boxes to pixel boxes upstream ([x*W, y*H, w*W, h*H]) if you cannot supply a canvas.
  3. Verify the probe logic: the node detects elements by any dict having a 'bbox' list, so mixed inputs still require a canvas.

Example fix

# before
elements = [{"bbox": [0.1, 0.2, 0.5, 0.4]}]  # canvas_width=0
# after
elements = [{"bbox": [0.1, 0.2, 0.5, 0.4]}]  # canvas_width=1024, canvas_height=768
Defensive patterns

Strategy: validation

Validate before calling

def has_elements(bboxes) -> bool:
    probe = bboxes if isinstance(bboxes, list) else [bboxes]
    if probe and isinstance(probe[0], list):
        probe = probe[0]
    return any(isinstance(b, dict) and isinstance(b.get("bbox"), (list, tuple)) for b in probe)

def ensure_canvas(bboxes, w, h):
    if has_elements(bboxes) and (w <= 0 or h <= 0):
        raise ValueError("supply canvas dims for normalized boxes")
    return w, h

Type guard

def is_element_box(b) -> bool:
    return isinstance(b, dict) and isinstance(b.get("bbox"), (list, tuple))

Prevention

When it happens

Trigger: Passing element dicts like {"bbox": [0.1, 0.2, 0.5, 0.4]} to the compositor node while canvas_width and/or canvas_height are 0 or were left at defaults that resolve to 0. Raw pixel boxes (plain lists) do not trigger this — only elements do.

Common situations: Wiring layout-detection output (normalized element boxes) into a compositor whose canvas size comes from another optional input that is disconnected; workflows where the canvas is meant to be derived from the image but the sizing link was forgotten.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/8cd846c161e1c3b7. Report an issue: GitHub.