intelligent-control-lab / guard

MIT License
39 stars 6 forks source link

viewer has no cam attribute #7

Closed esquires closed 4 months ago

esquires commented 4 months ago

Greetings, thanks for posting this project.

I am running into an issue when trying to render the environment. Here is some code to recreate it (I am running it in the cpo directory).

import os
os.sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))

from utils.safe_rl_env_config import configuration
from  safe_rl_envs.envs.engine import Engine as  safe_rl_envs_Engine

def main() -> None:
    cfg = configuration("Goal_Point_8Hazards")
    env =  safe_rl_envs_Engine(cfg)

    obs = env.reset()

    while True:
        _, _, done, _ = env.step(env.action_space.sample())
        env.render()

if __name__ == '__main__':
    main()

On the env.render() line I get this traceback:

Traceback (most recent call last):
  File "/home/user/guard/safe_rl_lib/cpo/viewer.py", line 20, in <module>
    main()
  File "/home/user/guard/safe_rl_lib/cpo/viewer.py", line 16, in main
    env.render()
  File "/home/user/guard/safe_rl_envs/safe_rl_envs/envs/engine.py", line 689, in render
    self.viewer_setup()  
  File "/home/user/guard/safe_rl_envs/safe_rl_envs/envs/engine.py", line 2258, in viewer_setup
    self.viewer.cam.distance = 6
AttributeError: 'NoneType' object has no attribute 'cam'
[1]    14837 segmentation fault (core dumped)  python viewer.py

Is there a recommended way to call render? Thanks!

esquires commented 4 months ago

It looks like upgrading mujoco (pip install --upgrade mujoco) fixed it. It is working for version mujoco==3.1.5