rohanpsingh / mujoco-python-viewer

Simple renderer for use with MuJoCo (>=2.1.2) Python Bindings.
BSD 2-Clause "Simplified" License
163 stars 24 forks source link

Cannot start viewer after closing #8

Closed surgura closed 2 years ago

surgura commented 2 years ago

Whenever I run a simulation, close it, and restart a second one the window only shows a black screen. Do other people have this issue as well?

rohanpsingh commented 2 years ago

You mean after you close your program and then restart it? Or close the viewer programmatically and then reopen it?

surgura commented 2 years ago

The latter. Excuse me, I should have included a minimal example. Running mujoco viewer's sample.py multiple times within the same python script leads to a black window the second time on my machine:

import mujoco
import mujoco_viewer

while True:
    model = mujoco.MjModel.from_xml_path("humanoid.xml")
    data = mujoco.MjData(model)

    # create the viewer object
    viewer = mujoco_viewer.MujocoViewer(model, data)

    # simulate and render
    for _ in range(100):
        mujoco.mj_step(model, data)
        viewer.render()

    # close
    viewer.close()
rohanpsingh commented 2 years ago

Hi @surgura Thanks for the minimal example.

I could reproduce the problem, and it seems to have happened because mujoco context wasn't being freed (only made available after mujoco 2.1.2) Could you retry after updating mujoco-python-viewer? This will also update your mujoco to 2.1.5

surgura commented 2 years ago

Definitely working now. Thank you very much for the quick effort!

rohanpsingh commented 2 years ago

Nice!