mujoco-py icon indicating copy to clipboard operation
mujoco-py copied to clipboard

render window does not close

Open joeljosephjin opened this issue 5 years ago • 5 comments

Describe the bug This is the code I am running.

#Importing OpenAI gym package and MuJoCo engine
import gym
import mujoco_py

#Setting MountainCar-v0 as the environment
env = gym.make('HalfCheetah-v2')
# env = gym.make('MountainCar-v0')

#Sets an initial state
env.reset()

# Rendering our instance 300 times
for _ in range(300):
  #renders the environment
  env.render()

  #Takes a random action from its action space 
  # aka the number of unique actions an agent can perform
  env.step(env.action_space.sample())
env.close()

It runs fine, but then the render window doesn't close. Even when I do env.close() again, it doesn't close. I am runnning the code on jupyter notebook, in ubuntu. When I try to manually click close, the window becomes non-responsive and the dialog box pops up where I click 'Force Quit'. The window closes but then the jupyter kernel restarts.

I don't face the problem when I use MountainCar instead of the MuJoCo environment.

joeljosephjin avatar Sep 24 '20 10:09 joeljosephjin

I also experience the same issue on Jupyter

nerkulec avatar Dec 30 '20 17:12 nerkulec

I have the same issue, I fixed it by:

import glfw
glfw.terminate()

kaigett avatar Apr 27 '21 11:04 kaigett

@kaigett it works - you'll need to restart the kernel though. :)

raeidsaqur avatar May 06 '21 22:05 raeidsaqur

env = gym.make("CarRacing-v0")
env.reset()
for i in range(1000):
    env.render()
    env.step(env.action_space.sample())
env.reset()
env.close()

This worked for me.

suvajit-patra avatar Dec 13 '21 20:12 suvajit-patra

I think CarRacing is in Box2d environment but not MUJOCO. MUJOCO requires glfw.terminate() for closing the window.

zhyang2226 avatar Aug 29 '22 03:08 zhyang2226