Skip to content

fix(core): make headless OpenGL display singletons thread-safe#4332

Open
ciscorn wants to merge 7 commits into
maplibre:mainfrom
ciscorn:fix-egl-singleton
Open

fix(core): make headless OpenGL display singletons thread-safe#4332
ciscorn wants to merge 7 commits into
maplibre:mainfrom
ciscorn:fix-egl-singleton

Conversation

@ciscorn

@ciscorn ciscorn commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

While experimenting with multi-threaded headless rendering with OpenGL + EGL in maplibre-native-rs, I found that concurrent headless renderer creation can race in the EGL display singleton.

terminate called after throwing an instance of 'std::runtime_error'
  what():  Switching OpenGL context failed.

This PR replaces the weak singleton cache with a process-lifetime singleton. I confirmed that this fixes the issue.

The GLX backend does not appear to hit the same display-handle lifetime issue as EGL, but I have observed occasional SEGV. Since it uses a similar weak singleton pattern, this PR applies the same approach to GLX too.

@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: 8e79cd0f91

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread platform/linux/src/headless_backend_egl.cpp Outdated
@ciscorn ciscorn changed the title fix(core): make headless EGL display singleton thread-safe fix(core): make headless OpenGL display singletons thread-safe Jun 7, 2026
ciscorn added a commit to maplibre/maplibre-native-rs that referenced this pull request Jun 19, 2026
Resolves #229.

Linux OpenGL rendering used GLX, which requires X11/Xvfb. This PR adds
an EGL context so headless OpenGL works without an X server (beneficial
for container environments), and makes EGL the default OpenGL context on
Linux.

### Feature changes

- `opengl`: OpenGL backend. The Linux default is now EGL (surfaceless,
no X server needed)
- `glx`: use the GLX (X11) context on Linux (the previous default)

### CI matrix

- Linux OpenGL jobs split into `egl` (no xvfb) and `glx` (xvfb).

### Blocker

- maplibre/maplibre-native#4332

### AI assistance

Claude was used for investigating MLN and coding assistance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant