Skip to content
Closed
Changes from all 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
41 changes: 21 additions & 20 deletions envpool/python/glfw_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,27 @@ def preload_windows_gl_dlls(
if resolved_dll_dir is None:
return
resolved_str = str(resolved_dll_dir)
if prepend_path:
path_entries = os.environ.get("PATH", "").split(os.pathsep)
if resolved_str not in path_entries:
filtered_entries = [entry for entry in path_entries if entry]
os.environ["PATH"] = os.pathsep.join([
resolved_str,
*filtered_entries,
])
if resolved_str not in _REGISTERED_DLL_DIRS:
_WINDOWS_DLL_HANDLES.append(os.add_dll_directory(resolved_str))
_REGISTERED_DLL_DIRS.add(resolved_str)
win_dll = getattr(ctypes, "WinDLL", None)
if win_dll is None:
return
for dll_name in ("libglapi.dll", "libgallium_wgl.dll", "opengl32.dll"):
dll_path = resolved_dll_dir / dll_name
dll_path_str = str(dll_path)
if dll_path.is_file() and dll_path_str not in _PRELOADED_DLL_PATHS:
_WINDOWS_DLL_HANDLES.append(win_dll(str(dll_path)))
_PRELOADED_DLL_PATHS.add(dll_path_str)
with _CONTEXT_LOCK:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid reacquiring the non-reentrant context lock

On Windows when ENVPOOL_DLL_DIR is set to a valid DLL directory, try_ensure_mujoco_glfw_context() already holds _CONTEXT_LOCK while constructing _GlfwContext, and _GlfwContext.__init__() calls preload_windows_gl_dlls(). This new with _CONTEXT_LOCK: therefore tries to acquire the same threading.Lock a second time in the same thread, causing the first GLFW context initialization to hang instead of rendering or falling back. Use an RLock or move the preload outside the outer locked region.

Useful? React with 馃憤聽/ 馃憥.

if prepend_path:
path_entries = os.environ.get("PATH", "").split(os.pathsep)
if resolved_str not in path_entries:
filtered_entries = [entry for entry in path_entries if entry]
os.environ["PATH"] = os.pathsep.join([
resolved_str,
*filtered_entries,
])
if resolved_str not in _REGISTERED_DLL_DIRS:
_WINDOWS_DLL_HANDLES.append(os.add_dll_directory(resolved_str))
_REGISTERED_DLL_DIRS.add(resolved_str)
win_dll = getattr(ctypes, "WinDLL", None)
if win_dll is None:
return
for dll_name in ("libglapi.dll", "libgallium_wgl.dll", "opengl32.dll"):
dll_path = resolved_dll_dir / dll_name
dll_path_str = str(dll_path)
if dll_path.is_file() and dll_path_str not in _PRELOADED_DLL_PATHS:
_WINDOWS_DLL_HANDLES.append(win_dll(str(dll_path)))
_PRELOADED_DLL_PATHS.add(dll_path_str)


def _glfw_error_details(glfw: object) -> str:
Expand Down
Loading