Comfy-Org/ComfyUI · error · ValueError

batch_index {batch_index} is out of range; DA3_GEOMETRY has

Error message

batch_index {batch_index} is out of range; DA3_GEOMETRY has batch size {B}.

What it means

DA3 mesh node raises this when batch_index is >= the batch dimension B of the depth tensor in da3_geometry. Each geometry carries one entry per input image; the node extracts a single frame to mesh, so the index must fall inside [0, B). Note the guard only checks the upper bound — a negative batch_index would wrap around Python-style rather than raise.

Source

Thrown at comfy_extras/nodes_depth_anything_3.py:510

                DA3Geometry.Input("da3_geometry"),
                io.Int.Input("batch_index", default=0, min=0, max=4096, tooltip="Which image of a batch to convert. Per-image vertex counts differ so batches cannot be stacked."),
                io.Int.Input("decimation", default=1, min=1, max=8, tooltip="Vertex stride. 1 = full resolution, 2 = half, etc."),
                io.Float.Input("discontinuity_threshold", default=0.04, min=0.0, max=1.0, step=0.01, tooltip="Drop triangles whose 3x3 depth span exceeds this fraction. 0 = off."),
                io.Float.Input("confidence_threshold", default=0.1, min=0.0, max=1.0, step=0.01,
                    tooltip="Exclude pixels whose per-image normalised confidence is below this value (0 = keep all, 1 = keep only the single most confident pixel). "
                        "Used when the geometry has a confidence map (Small/Base models)."),
                io.Boolean.Input("use_sky_mask", default=True, tooltip="Exclude sky-probability pixels (sky >= 0.5) from the mesh. Used when the geometry has a sky map (Mono/Metric models)."),
                io.Boolean.Input("texture", default=True, tooltip="Use the source image as a base color texture."),
            ],
            outputs=[io.Mesh.Output()],
        )

    @classmethod
    def execute(cls, da3_geometry, batch_index, decimation, discontinuity_threshold, confidence_threshold, use_sky_mask, texture) -> io.NodeOutput:
        depth_all = da3_geometry["depth"]   # (B, H, W)
        B = depth_all.shape[0]
        if batch_index >= B:
            raise ValueError(f"batch_index {batch_index} is out of range; DA3_GEOMETRY has batch size {B}.")

        depth = depth_all[batch_index]      # (H, W)
        H, W = depth.shape

        # NaN/inf depth would propagate silently through unproject and produce an
        # empty mesh; replace them with 0 here so those pixels are later excluded
        # by the isfinite check inside triangulate_grid_mesh.
        depth = depth.clone()
        n_bad = (~torch.isfinite(depth)).sum().item()
        if n_bad:
            logging.getLogger("comfy").warning(
                f"DA3GeometryToMesh: depth[{batch_index}] has {n_bad} non-finite pixels "
                f"({100*n_bad/(H*W):.1f}%) - zeroed before unproject."
            )
        depth[~torch.isfinite(depth)] = 0.0
        logging.getLogger("comfy").debug(
            f"DA3GeometryToMesh: depth[{batch_index}] range "
            f"[{depth.min():.4g}, {depth.max():.4g}], mean={depth.mean():.4g}"

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Set batch_index to a value in [0, B-1]; for single images use 0.
  2. Check the upstream DA3 node's image batch size and align the index.
  3. Remember batch_index is 0-based.
Defensive patterns

Strategy: validation

Validate before calling

B = da3_geometry['depth'].shape[0]
if not (0 <= batch_index < B):
    raise IndexError(f'batch_index must be in [0, {B-1}]')  # also catches negatives the node misses

Prevention

When it happens

Trigger: Upstream DA3 node processed a single image (B=1) but batch_index is set to 1 or higher; or a batch was reduced after the index was configured.

Common situations: Index left over from a batch run (e.g. batch_index=5) after switching to a single-image input; off-by-one from assuming batch_index is 1-based.

Related errors


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