Skip to content

Commit 81d8298

Browse files
bottlerfacebook-github-bot
authored andcommitted
Fix ogl test hang
Summary: See #1908 Reviewed By: MichaelRamamonjisoa Differential Revision: D65280253 fbshipit-source-id: ec05902c5f2f7eb9ddd92bda0045cc3564b8c091
1 parent 8fe6934 commit 81d8298

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

pytorch3d/renderer/opengl/opengl_utils.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def __init__(self, width: int, height: int, cuda_device_id: int = 0) -> None:
184184
"""
185185
# Lock used to prevent multiple threads from rendering on the same device
186186
# at the same time, creating/destroying contexts at the same time, etc.
187-
self.lock = threading.Lock()
187+
self.lock = threading.RLock()
188188
self.cuda_device_id = cuda_device_id
189189
self.device = _get_cuda_device(self.cuda_device_id)
190190
self.width = width
@@ -224,15 +224,14 @@ def active_and_locked(self):
224224
Throws:
225225
EGLError when the context cannot be made current or make non-current.
226226
"""
227-
self.lock.acquire()
228-
egl.eglMakeCurrent(self.dpy, self.surface, self.surface, self.context)
229-
try:
230-
yield
231-
finally:
232-
egl.eglMakeCurrent(
233-
self.dpy, egl.EGL_NO_SURFACE, egl.EGL_NO_SURFACE, egl.EGL_NO_CONTEXT
234-
)
235-
self.lock.release()
227+
with self.lock:
228+
egl.eglMakeCurrent(self.dpy, self.surface, self.surface, self.context)
229+
try:
230+
yield
231+
finally:
232+
egl.eglMakeCurrent(
233+
self.dpy, egl.EGL_NO_SURFACE, egl.EGL_NO_SURFACE, egl.EGL_NO_CONTEXT
234+
)
236235

237236
def get_context_info(self) -> Dict[str, Any]:
238237
"""

0 commit comments

Comments
 (0)