Skip to content

Accept GLEW_ERROR_NO_GLX_DISPLAY from glewInit() in scenes 2 to 4 - #60

Merged
deadbeef7 merged 1 commit into
deadbeef7:masterfrom
hegjon:fix/glewinit-wayland
Nov 10, 2026
Merged

deadbeef7 merged 1 commit into
deadbeef7:masterfrom
hegjon:fix/glewinit-wayland

Conversation

@hegjon

@hegjon hegjon commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

On Linux under Wayland, scenes 2 to 4 (--scene-only, --pool-only, --pole-only) exit right after the window opens:

$ SDL_VIDEODRIVER=wayland ./ElectroBench --scene-only
glewInit failed

Scene 1 (--og-only) runs. Without SDL_VIDEODRIVER the program takes X11 through XWayland and works. Without a DISPLAY it does not start at all, because SDL 2 (sdl2-compat) tries X11 first.

Why

Most Linux distributions build GLEW for GLX. Arch's GLEW 2.3.1 is one of them. On Wayland, SDL creates an EGL context. glewInit() loads every GL function through it, then looks for a GLX display. There isn't one, so it returns GLEW_ERROR_NO_GLX_DISPLAY, even though nothing is missing.

Scene 1 ignores the return value, so it runs. Scenes 2 to 4 check it and exit.

The change

Scenes 2 to 4 now accept GLEW_ERROR_NO_GLX_DISPLAY. For any other error they print glewGetErrorString()'s text and exit as before:

GLenum glewError = glewInit();
if (glewError != GLEW_OK && glewError != GLEW_ERROR_NO_GLX_DISPLAY) {
  std::fprintf(stderr, "glewInit failed: %s\n", glewGetErrorString(glewError));
  return EXIT_FAILURE;
}

GLEW_ERROR_NO_GLX_DISPLAY has been in glew.h since GLEW 2.0. A GLEW built for EGL returns GLEW_OK here, so it isn't affected, and neither is Windows.

Tested

Tested on Arch Linux with GLEW 2.3.1 and sdl2-compat 2.32.74, on Wayland under Hyprland 0.57 and a fork of it. Each scene ran with SDL_VIDEODRIVER=wayland and no XWayland involved, then printed its results.

GPU Mesa driver Ocean (fullscreen) Pool (--windowed) Power lines (fullscreen)
Intel HD 4000 (Ivy Bridge) crocus 26.2.6 6.1 fps 9.1 26.7
Intel HD 5000 (Haswell) crocus 26.2.6 10.1 13.5 44.4
Intel HD Graphics (Bay Trail) crocus 26.2.6 2.3 5.3 12.1
Intel HD 5500 (Broadwell), two laptops iris 26.2.6 10.5 / 5.4 15.5 / 6.2 36.0 / 14.4
Intel HD 520 (Skylake) iris 26.2.6 12.3 19.2 48.4
Intel UHD 620 (Whiskey Lake) iris 26.2.6 12.9 19.9 48.6
AMD Radeon HD 8570D (Aruba) r600 26.2.6 9.9 14.3 35.5
Qualcomm Adreno X1-85 freedreno 26.2.6 13.6 49.6 103.6
Apple M1 asahi 26.3.0-devel 53.5 83.8 193.5

On an Intel GM45, which has no OpenGL 3.3, scene 4 still exits cleanly with the existing "no OpenGL 3.3 core context" message. Scene 1 runs there as before.

One more thing, not part of this change: --scene-only, --pool-only and --pole-only report any start-up failure as "no OpenGL 3.3 core context on this device". On a machine with no display connected, the real error was SDL's "The video driver did not add any displays".

🤖 Generated with Claude Code

GLEW built for GLX, as most Linux distributions ship it (Arch's 2.3.1),
loads every GL function on an EGL context too, which is what SDL creates
on Wayland, and then returns GLEW_ERROR_NO_GLX_DISPLAY because there is
no GLX display. Scenes 2 to 4 took that for a failure and exited with
"glewInit failed", so they only ran through XWayland. Scene 1 ignores
what glewInit() returns and ran either way.

Accept that error, and print the error string for any other.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@deadbeef7

Copy link
Copy Markdown
Owner

also thanks for the score sheet lmao I'm building a leaderboard

@deadbeef7
deadbeef7 marked this pull request as ready for review November 10, 2026 17:18
@deadbeef7
deadbeef7 merged commit c8c264a into deadbeef7:master Nov 10, 2026
1 check passed
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.

2 participants