File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 77import mujoco
88import numpy as np
99
10+ from gymnasium .logger import warn
11+
1012
1113def _import_egl (width , height ):
1214 from mujoco .egl import GLContext
@@ -356,11 +358,22 @@ def make_context_current(self):
356358 glfw .make_context_current (self .window )
357359
358360 def free (self ):
359- if self .window :
360- if glfw .get_current_context () == self .window :
361- glfw .make_context_current (None )
362- glfw .destroy_window (self .window )
363- self .window = None
361+ """
362+ Safely frees the OpenGL context and destroys the GLFW window,
363+ handling potential issues during interpreter shutdown or resource cleanup.
364+ """
365+ try :
366+ if self .window :
367+ if glfw .get_current_context () == self .window :
368+ glfw .make_context_current (None )
369+ glfw .destroy_window (self .window )
370+ self .window = None
371+ except AttributeError :
372+ # Handle cases where attributes are missing due to improper environment closure
373+ warn (
374+ "Environment was not properly closed using 'env.close()'. Please ensure to close the environment explicitly. "
375+ "GLFW module or dependencies are unloaded. Window cleanup might not have completed."
376+ )
364377
365378 def __del__ (self ):
366379 """Eliminate all of the OpenGL glfw contexts and windows"""
You can’t perform that action at this time.
0 commit comments