Add a close() method to mujoco.Renderer which explicitly frees the gl context.

PiperOrigin-RevId: 590221484
Change-Id: I07392f9c53f662a37a57ab23acfef9aa5a98a49b
This commit is contained in:
Kevin Zakka
2023-12-12 08:58:49 -08:00
committed by Copybara-Service
parent e3df84ec3f
commit 53883ce86a
4 changed files with 100 additions and 62 deletions
+11 -8
View File
@@ -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()