{"record":{"id":"2460b14eedc033d5","repo":"Comfy-Org/ComfyUI","slug":"batch-index-batch-index-out-of-range-moge-geome","errorCode":null,"errorMessage":"batch_index {batch_index} out of range; moge_geometry has batch size {B}.","messagePattern":"batch_index (.+?) out of range; moge_geometry has batch size (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_moge.py","lineNumber":364,"sourceCode":"                                     \"differ, so batches can't be stacked into a single MESH.\"),\n                io.Int.Input(\"decimation\", default=1, min=1, max=8,\n                             tooltip=\"Vertex stride; 1 = full resolution.\"),\n                io.Float.Input(\"discontinuity_threshold\", default=0.04, min=0.0, max=1.0, step=0.01,\n                               tooltip=\"Drop pixels whose 3x3 depth span exceeds this fraction. 0 = off.\"),\n                io.Boolean.Input(\"texture\", default=True,\n                                 tooltip=\"Carry the source image through as the baseColor texture.\"),\n            ],\n            outputs=[io.Mesh.Output()],\n        )\n\n    @classmethod\n    def execute(cls, moge_geometry, batch_index, decimation, discontinuity_threshold, texture) -> io.NodeOutput:\n        if \"points\" not in moge_geometry:\n            raise ValueError(\"moge_geometry has no points output.\")\n        points = moge_geometry[\"points\"]\n        B = points.shape[0]\n        if batch_index >= B:\n            raise ValueError(f\"batch_index {batch_index} out of range; moge_geometry has batch size {B}.\")\n\n        # Pass depth so the rtol edge check sees radial depth -- for panoramas\n        # points[..., 2] = cos(phi)*r goes negative below the equator and the rtol clamp would drop the bottom half.\n        edge_depth = moge_geometry[\"depth\"][batch_index] if \"depth\" in moge_geometry else None\n        verts, faces, uvs = triangulate_grid_mesh(\n            points[batch_index], decimation=decimation,\n            discontinuity_threshold=discontinuity_threshold, depth=edge_depth,\n        )\n        if verts.shape[0] == 0 or faces.shape[0] == 0:\n            raise ValueError(\"MoGe produced an empty mesh; try discontinuity_threshold=0 or apply_mask=False.\")\n\n        if \"intrinsics\" not in moge_geometry:\n            # Panorama: rotate MoGe spherical (Z up) -> glTF (Y up, Z back), correct for inside-the-sphere viewing)\n            verts = verts[:, [1, 2, 0]].contiguous()\n        else:\n            # Perspective MoGe (X right, Y down, Z forward) -> glTF; face flip keeps winding CCW after the Y/Z flip.\n            verts = verts * torch.tensor([1.0, -1.0, -1.0], dtype=verts.dtype)\n            faces = faces[:, [0, 2, 1]].contiguous()","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_moge.py#L346-L382","documentation":"The mesh node exports one batch element at a time; batch_index must be < points.shape[0]. An index equal to or above the geometry's batch size is rejected (note the lower bound is not re-checked here because the input widget already enforces min=0).","triggerScenarios":"batch_index >= B, e.g. batch_index=1 on a single-image geometry, or a stale index after switching from a multi-image batch to a single image upstream.","commonSituations":"Workflows with a fixed batch_index from a batched run later fed single images; UI widgets remembering a previous higher index.","solutions":["Set batch_index to a value in [0, B-1]; check B via points.shape[0].","For batched inputs, loop over indices or insert a batch-split node before meshing.","Reset the widget value to 0 when switching to single-image geometry."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"B = moge_geometry['points'].shape[0]\nif not 0 <= batch_index < B:\n    raise UserFacingError(f'batch_index must be in [0, {B - 1}]')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Reset batch_index to 0 when switching to single-image geometry.","Derive batch_index from points.shape[0] programmatically.","Split batches before meshing instead of indexing past the end."],"tags":["moge","mesh","batch-index","bounds"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}