Add a close() method to mujoco.Renderer which explicitly frees the gl context.
PiperOrigin-RevId: 590221484 Change-Id: I07392f9c53f662a37a57ab23acfef9aa5a98a49b
This commit is contained in:
committed by
Copybara-Service
parent
e3df84ec3f
commit
53883ce86a
@@ -57,15 +57,18 @@ class GLContext:
|
||||
|
||||
def free(self):
|
||||
"""Frees resources associated with this context."""
|
||||
if self._context:
|
||||
cgl.CGLUnlockContext(self._context)
|
||||
cgl.CGLSetCurrentContext(None)
|
||||
cgl.CGLReleaseContext(self._context)
|
||||
self._context = None
|
||||
try:
|
||||
if self._context:
|
||||
cgl.CGLUnlockContext(self._context)
|
||||
cgl.CGLSetCurrentContext(None)
|
||||
cgl.CGLReleaseContext(self._context)
|
||||
self._context = None
|
||||
|
||||
if self._pix:
|
||||
cgl.CGLReleasePixelFormat(self._pix)
|
||||
self._context = None
|
||||
if self._pix:
|
||||
cgl.CGLReleasePixelFormat(self._pix)
|
||||
self._pix = None
|
||||
except Exception: # pylint: disable=broad-exception-caught
|
||||
pass
|
||||
|
||||
def __del__(self):
|
||||
self.free()
|
||||
|
||||
Reference in New Issue
Block a user