Skip to content

Commit db8be74

Browse files
hobostayTest User
andauthored
fix(jumanji): prevent IndexError in routing render when no valid nodes (#416)
## Summary Fix an IndexError in the Jumanji routing renderer's `build_edges()` method that crashes when an agent has no valid connected nodes. ## Root Cause In `envpool/jumanji/_official_render/routing.py` line 656: ```python len_conn = np.where(conn_group != -1)[0][-1] ``` When `conn_group` contains only `-1` values (no valid connected nodes for an agent), `np.where(conn_group != -1)[0]` returns an empty array. Accessing `[-1]` on an empty array raises `IndexError`. ## Fix Add a guard to check if there are valid indices before proceeding: ```python valid_indices = np.where(conn_group != -1)[0] if len(valid_indices) == 0: continue len_conn = valid_indices[-1] ``` ## Test plan - [x] Verify rendering works when all agents have valid connected nodes - [x] Verify no crash when an agent has no valid connected nodes Co-authored-by: Test User <test@example.com>
1 parent 8b8d973 commit db8be74

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

envpool/jumanji/_official_render/routing.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,10 @@ def edge_id(n1: int, n2: int) -> tuple[int, ...]:
653653

654654
for agent in range(self.num_agents):
655655
conn_group = connected_nodes[agent]
656-
len_conn = np.where(conn_group != -1)[0][-1]
656+
valid_indices = np.where(conn_group != -1)[0]
657+
if len(valid_indices) == 0:
658+
continue
659+
len_conn = valid_indices[-1]
657660
for i in range(len_conn):
658661
key = edge_id(conn_group[i], conn_group[i + 1])
659662
edges[key] = [

0 commit comments

Comments
 (0)