Skip to content

Commit 62b22df

Browse files
authored
Merge pull request #13 from KraHsu/fix/play-viewer-crashes
Fix viewer crashes on first play and on window close
2 parents d47ba96 + 18dfef2 commit 62b22df

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎src/genelab/cache.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ def ensure_project_cache() -> None:
1414

1515
XDG_CACHE_DIR.mkdir(parents=True, exist_ok=True)
1616
MATPLOTLIB_CACHE_DIR.mkdir(parents=True, exist_ok=True)
17+
(XDG_CACHE_DIR / "genesis").mkdir(parents=True, exist_ok=True)
1718
os.environ.setdefault("XDG_CACHE_HOME", str(XDG_CACHE_DIR))
1819
os.environ.setdefault("MPLCONFIGDIR", str(MATPLOTLIB_CACHE_DIR))

‎src/genelab/rl/runner.py‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ def play_task(
166166
env = _build_env(env_cfg)
167167
wrapped = RslRlVecEnvWrapper(env, clip_actions=None)
168168

169+
import genesis as gs # type: ignore[import-not-found]
169170
import torch
170171

171172
action_shape = (env.num_envs, wrapped.num_actions)
@@ -213,7 +214,12 @@ def _random_policy(_obs: Any) -> "torch.Tensor":
213214
while True:
214215
with torch.inference_mode():
215216
actions = policy(obs)
216-
obs, _, _, _ = wrapped.step(actions)
217+
try:
218+
obs, _, _, _ = wrapped.step(actions)
219+
except gs.GenesisException as exc:
220+
if str(exc) != "Viewer closed.":
221+
raise
222+
break
217223
step += 1
218224
if max_steps is not None and step >= max_steps:
219225
break

0 commit comments

Comments
 (0)