Skip to content

[BUG FIX] Prevent pyglet's headless display from terminating the offscreen EGL context.#2953

Merged
duburcqa merged 4 commits into
Genesis-Embodied-AI:mainfrom
duburcqa:offscreen_gl_teardown_gc_safe
Jun 16, 2026
Merged

[BUG FIX] Prevent pyglet's headless display from terminating the offscreen EGL context.#2953
duburcqa merged 4 commits into
Genesis-Embodied-AI:mainfrom
duburcqa:offscreen_gl_teardown_gc_safe

Conversation

@duburcqa

Copy link
Copy Markdown
Collaborator

Description

try_get_display_size queried pyglet's display via get_display(), which in a headless process creates pyglet's
placeholder HeadlessDisplay. That object is only weakly referenced, so it is garbage-collected, and its __del__
calls eglTerminate on the shared EGL display - invalidating the live contexts of genesis's offscreen renderers
(seen as EGL_BAD_CONTEXT mid-render). It now resolves pyglet's native display backend directly, so a headless
process reports no display rather than spawning the headless one whose finalizer does the damage.

Separately, offscreen renderer teardown (Rasterizer.destroy) now saves and restores the current GL context. The
current context is process/thread-global; freeing one renderer makes its own context current, which previously left
another renderer mid-render stranded.

Motivation and Context

Root cause of intermittent offscreen-render failures (the flaky CI that #2951 worked around). Reproduced under EGL
(Mesa llvmpipe and NVIDIA GPU) and on Metal.

How Has This Been / Can This Be Tested?

New regression test tests/test_render.py::test_offscreen_context_isolation: destroys one offscreen scene mid-render
of another and asserts the survivor's output is unchanged. Verified on Metal, EGL (NVIDIA GPU + Mesa llvmpipe), with
both pyglet 1.5 and 2.1.

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@duburcqa duburcqa requested a review from YilingQiao as a code owner June 16, 2026 07:19
@duburcqa duburcqa force-pushed the offscreen_gl_teardown_gc_safe branch from a526fdd to 1ca93db Compare June 16, 2026 07:22

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a526fdd7eb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/vis/rasterizer.py Outdated
@duburcqa duburcqa force-pushed the offscreen_gl_teardown_gc_safe branch from 1ca93db to 1816be1 Compare June 16, 2026 07:35
@duburcqa duburcqa changed the title [BUG FIX] Prevent pyglet's headless display from terminating the offscreen EGL context [BUG FIX] Prevent pyglet's headless display from terminating the offscreen EGL context. Jun 16, 2026
@duburcqa duburcqa force-pushed the offscreen_gl_teardown_gc_safe branch from 1816be1 to cddfa03 Compare June 16, 2026 08:39
@duburcqa

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cddfa03e2e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/utils/misc.py
@duburcqa duburcqa merged commit bbdae27 into Genesis-Embodied-AI:main Jun 16, 2026
19 of 22 checks passed
@github-actions

Copy link
Copy Markdown

⚠️ Abnormal Benchmark Result Detected ➡️ Report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant