Skip to content

Commit ad7d644

Browse files
committed
fix(get_started): example 0 handles missing camera frames gracefully
Newton's SensorTiledCamera init can fail silently in environments without the required GL / Warp context (Newton already logs a "Cameras disabled. Error: ..." warning at handler launch). The example then crashed with an opaque ``StopIteration`` on: next(iter(obs_tensor.cameras.values())) because the cameras dict was empty. Guard the save: when ``obs_tensor.cameras`` is empty, log a human-readable warning pointing the user at the earlier backend- side init failure and skip the imageio call. Same example body across all other backends (mujoco / sapien3 / pybullet / isaacsim) is unaffected. Verified by running get_started/0_static_scene.py across mujoco, sapien3, pybullet, newton (newton now exits cleanly with the new 'No camera frames available' warning instead of the StopIteration).
1 parent 8322a18 commit ad7d644

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

get_started/0_static_scene.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ def __post_init__(self):
172172

173173
os.makedirs("get_started/output", exist_ok=True)
174174
save_path = f"get_started/output/0_static_scene_{args.sim}.png"
175-
log.info(f"Saving image to {save_path}")
176-
imageio.imwrite(save_path, next(iter(obs_tensor.cameras.values())).rgb[0].cpu().numpy())
175+
if not obs_tensor.cameras:
176+
# Newton's SensorTiledCamera init can fail in environments without
177+
# the required GL/Warp context (logs a "Cameras disabled" warning
178+
# at handler launch). Don't StopIteration on the user — explain.
179+
log.warning(
180+
f"No camera frames available from {args.sim}; skipping image save. "
181+
f"Check earlier logs for backend-side camera-init warnings."
182+
)
183+
else:
184+
log.info(f"Saving image to {save_path}")
185+
imageio.imwrite(save_path, next(iter(obs_tensor.cameras.values())).rgb[0].cpu().numpy())
177186
handler.close()

0 commit comments

Comments
 (0)