{"record":{"id":"75f588cb1e307ee2","repo":"Comfy-Org/ComfyUI","slug":"batch-index-batch-index-is-out-of-range-da3-geo","errorCode":null,"errorMessage":"batch_index {batch_index} is out of range; DA3_GEOMETRY has batch size {B}.","messagePattern":"batch_index (.+?) is out of range; DA3_GEOMETRY has batch size (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_depth_anything_3.py","lineNumber":510,"sourceCode":"                DA3Geometry.Input(\"da3_geometry\"),\n                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.\"),\n                io.Int.Input(\"decimation\", default=1, min=1, max=8, tooltip=\"Vertex stride. 1 = full resolution, 2 = half, etc.\"),\n                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.\"),\n                io.Float.Input(\"confidence_threshold\", default=0.1, min=0.0, max=1.0, step=0.01,\n                    tooltip=\"Exclude pixels whose per-image normalised confidence is below this value (0 = keep all, 1 = keep only the single most confident pixel). \"\n                        \"Used when the geometry has a confidence map (Small/Base models).\"),\n                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).\"),\n                io.Boolean.Input(\"texture\", default=True, tooltip=\"Use the source image as a base color texture.\"),\n            ],\n            outputs=[io.Mesh.Output()],\n        )\n\n    @classmethod\n    def execute(cls, da3_geometry, batch_index, decimation, discontinuity_threshold, confidence_threshold, use_sky_mask, texture) -> io.NodeOutput:\n        depth_all = da3_geometry[\"depth\"]   # (B, H, W)\n        B = depth_all.shape[0]\n        if batch_index >= B:\n            raise ValueError(f\"batch_index {batch_index} is out of range; DA3_GEOMETRY has batch size {B}.\")\n\n        depth = depth_all[batch_index]      # (H, W)\n        H, W = depth.shape\n\n        # NaN/inf depth would propagate silently through unproject and produce an\n        # empty mesh; replace them with 0 here so those pixels are later excluded\n        # by the isfinite check inside triangulate_grid_mesh.\n        depth = depth.clone()\n        n_bad = (~torch.isfinite(depth)).sum().item()\n        if n_bad:\n            logging.getLogger(\"comfy\").warning(\n                f\"DA3GeometryToMesh: depth[{batch_index}] has {n_bad} non-finite pixels \"\n                f\"({100*n_bad/(H*W):.1f}%) - zeroed before unproject.\"\n            )\n        depth[~torch.isfinite(depth)] = 0.0\n        logging.getLogger(\"comfy\").debug(\n            f\"DA3GeometryToMesh: depth[{batch_index}] range \"\n            f\"[{depth.min():.4g}, {depth.max():.4g}], mean={depth.mean():.4g}\"","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_depth_anything_3.py#L492-L528","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set batch_index to a value in [0, B-1]; for single images use 0.","Check the upstream DA3 node's image batch size and align the index.","Remember batch_index is 0-based."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"B = da3_geometry['depth'].shape[0]\nif not (0 <= batch_index < B):\n    raise IndexError(f'batch_index must be in [0, {B-1}]')  # also catches negatives the node misses","typeGuard":null,"tryCatchPattern":null,"preventionTips":["batch_index is 0-based; single-image geometries always use 0.","Check geometry['depth'].shape[0] before setting the index.","Note the node only guards the upper bound, so validate negatives yourself."],"tags":["comfyui","depth-anything-3","index-out-of-range","mesh"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}