Comfy-Org/ComfyUI · error · ValueError

Cannot create grid from empty image list

Error message

Cannot create grid from empty image list

What it means

Thrown by the grid-layout helper when the incoming image list is empty: a grid of zero images has no dimensions, so the node refuses instead of producing a blank/degenerate image. It fires before any grid math (rows, width, height) runs.

Source

Thrown at comfy_extras/nodes_dataset.py:1671

        ),
        io.Int.Input(
            "cell_height",
            default=256,
            min=32,
            max=2048,
            tooltip="Height of each cell in the grid.",
            advanced=True,
        ),
        io.Int.Input(
            "padding", default=4, min=0, max=50, tooltip="Padding between images.", advanced=True
        ),
    ]

    @classmethod
    def _group_process(cls, images, columns, cell_width, cell_height, padding):
        """Arrange images into a grid."""
        if len(images) == 0:
            raise ValueError("Cannot create grid from empty image list")

        # Calculate grid dimensions
        num_images = len(images)
        rows = (num_images + columns - 1) // columns  # Ceiling division

        # Calculate total grid size
        grid_width = columns * cell_width + (columns - 1) * padding
        grid_height = rows * cell_height + (rows - 1) * padding

        # Create blank grid
        grid = Image.new("RGB", (grid_width, grid_height), (0, 0, 0))

        # Place images
        for idx, img_tensor in enumerate(images):
            row = idx // columns
            col = idx % columns

            # Convert to PIL and resize to cell size

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Check the upstream node: verify the loader/filter actually produced images (inspect its output count).
  2. Add a conditional in the workflow or wrapper code: skip the grid node when len(images) == 0.
  3. Loosen or fix the upstream filter so at least one image survives.

Example fix

# before
grid = node._group_process(images, columns=4, cell_width=256, cell_height=256, padding=4)
# after
if not images:
    raise ValueError('upstream loader returned no images; check its filter')
grid = node._group_process(images, columns=4, cell_width=256, cell_height=256, padding=4)
Defensive patterns

Strategy: validation

Validate before calling

if not images:
    raise ValueError('upstream loader returned 0 images; fix the loader/filter before building a grid')

Type guard

def has_images(imgs: list) -> bool:
    return len(imgs) > 0

Prevention

When it happens

Trigger: Feeding the grid node an empty image list: an empty batch from an upstream loader (e.g. LoadImage batch of zero, a dataset/loader that filtered out every item, or an empty list literal wired into the input).

Common situations: Dataset or directory loaders where a filter (extension, resolution, text match) removed all items; batch-processing pipelines where one iteration legitimately produces zero images; preview/inspection nodes wired to a list that can be empty.

Related errors


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