Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] TypeError: 'NoneType' object is not callable in /mujoco_rendering.py in free #438

Closed
1 task done
sonelu opened this issue Apr 7, 2023 · 6 comments · Fixed by #440
Closed
1 task done
Labels
bug Something isn't working

Comments

@sonelu
Copy link
Contributor

sonelu commented Apr 7, 2023

Describe the bug

When closing an environment that used env.render() the following dump is issued:

Exception ignored in: <function WindowViewer.__del__ at 0x7fcc0d2530e0>
Traceback (most recent call last):
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 335, in __del__
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 330, in free
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 1274, in destroy_window
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 687, in errcheck
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 70, in _reraise
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 666, in callback_wrapper
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 912, in _handle_glfw_errors
TypeError: 'NoneType' object is not callable

https://github.com/Farama-Foundation/Gymnasium/blob/3923e35a18b5e1c1936ce5878c10f49a3cc94ed3/gymnasium/envs/mujoco/mujoco_rendering.py#L326-331

    def free(self):
        if self.window:
            if glfw.get_current_context() == self.window:
                glfw.make_context_current(None)
        glfw.destroy_window(self.window)
        self.window = None

Changing the code to this seems to remove the error:

    def free(self):
        if self.window:
            if glfw.get_current_context() == self.window:
                glfw.make_context_current(None)
            glfw.destroy_window(self.window)
            self.window = None

Code example

No response

System info

Describe how Gymnasium was installed: pip
Version of gymnasium: 0.28.1
What OS/version of Linux you're using. Note that while we will accept PRs to improve Window's support, we do not officially support it.: 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux (Ubuntu 22.04 under WSL2)
Python version: 3.7.12

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@sonelu sonelu added the bug Something isn't working label Apr 7, 2023
@pseudo-rnd-thoughts
Copy link
Member

Thanks @sonelu, could you make a PR to add your change

sonelu added a commit to sonelu/Gymnasium that referenced this issue Apr 7, 2023
@Kallinteris-Andreas
Copy link
Collaborator

I can not replicate @sonelu show me the steps to replicate

@pseudo-rnd-thoughts
Copy link
Member

@Kallinteris-Andreas Are you using windows wsl?

@Kallinteris-Andreas
Copy link
Collaborator

@pseudo-rnd-thoughts no i run arch

@sonelu
Copy link
Contributor Author

sonelu commented Apr 7, 2023

Code:

import gymnasium as gym

env = gym.make('Humanoid-v4', render_mode='human')

env.reset()

for _ in range(100):
    action = env.action_space.sample()
    obs, rew, term, trunc, info =  env.step(action)
    env.render()
    if term or trunc:
        env.reset()

env.close()

Dump

(sb3) ml@Alex4:~/Learning/sacv$ python render.py
Exception ignored in: <function WindowViewer.__del__ at 0x7ffafaa9f290>
Traceback (most recent call last):
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 335, in __del__
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/gymnasium/envs/mujoco/mujoco_rendering.py", line 330, in free
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 1274, in destroy_window
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 687, in errcheck
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 70, in _reraise
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 666, in callback_wrapper
  File "/home/ml/mambaforge-pypy3/envs/sb3/lib/python3.7/site-packages/glfw/__init__.py", line 912, in _handle_glfw_errors
TypeError: 'NoneType' object is not callable

@Kallinteris-Andreas
Copy link
Collaborator

Thanks, I can replicate now, bug is only present with render_mode='human' (which was not stated in the initial post)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants