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

Add error message when terminating the MuJoCo renderer without calling env.close #1283

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions gymnasium/envs/mujoco/mujoco_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,20 @@ def make_context_current(self):
glfw.make_context_current(self.window)

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
"""
Safely frees the OpenGL context and destroys the GLFW window,
handling potential issues during interpreter shutdown or resource cleanup.
"""
try:
if self.window:
if glfw.get_current_context() == self.window:
glfw.make_context_current(None)
glfw.destroy_window(self.window)
self.window = None
except AttributeError:
a-ayesh marked this conversation as resolved.
Show resolved Hide resolved
# Handle cases where attributes are missing due to improper environment closure
print("""Warning: Environment was not properly closed using 'env.close()'. Please ensure to close the environment explicitly.
GLFW module or dependencies are unloaded. Window cleanup might not have completed.""")

def __del__(self):
"""Eliminate all of the OpenGL glfw contexts and windows"""
Expand Down
Loading