8000 egl: fall back to fewer samples when no config offers sample_count by benface · Pull Request #671 · not-fl3/miniquad · GitHub
[go: up one dir, main page]

Skip to content

egl: fall back to fewer samples when no config offers sample_count - #671

Open
benface wants to merge 1 commit into
not-fl3:masterfrom
benface:egl-sample-count-fallback
Open

benface wants to merge 1 commit into
not-fl3:masterfrom
benface:egl-sample-count-fallback

Conversation

@benface
@benface benface commented Oct 5, 2026
Copy link
Copy Markdown
Contributor

Why

create_egl_context passes Conf::sample_count straight to EGL_SAMPLES and asserts that eglChooseConfig found a config. So an app that asks for MSAA panics at launch on any device whose EGL has no config with that many samples:

panicked at src/native/egl.rs:209:5:
assertion failed: cfg_count > 0

The Android emulator is one of them. It offers configs with 0 samples and a single one with 1, so sample_count: 4 panics as soon as the surface exists. This happens on API 34 and API 36 images, with -gpu auto, host and swiftshader.

Change

Retry eglChooseConfig with half as many samples until a config matches, down to 0. If nothing matches at 0 either, the existing assert still fires.

  • When the requested count is available, the first query matches, so the config is the same as before.
  • sample_count: 1, the default, still asks for 1 sample first, so apps that don't ask for MSAA are unaffected.
  • The fallback costs at most a few extra eglChooseConfig calls, and only during context creation.

The fallback is in the shared EGL path, so it covers every create_egl_context caller: Android and the Linux X11 and Wayland EGL backends.

Verification

  • On the Android emulator (API 34, -gpu auto), 4 and 2 samples match nothing and 1 matches. A macroquad game (CHOMP) that sets sample_count: 4 now starts and renders instead of panicking.
  • cargo check passes with no new warnings for aarch64-linux-android and x86_64-unknown-linux-gnu.

🤖 Generated with Claude Code

`create_egl_context` passes `Conf::sample_count` straight to
`EGL_SAMPLES` and asserts that `eglChooseConfig` found a config, so
an app that asks for MSAA panics at launch on any device whose EGL
has no config with that many samples. The Android emulator is one:
it offers configs with 0 samples and a single one with 1, so
`sample_count: 4` fails with `assertion failed: cfg_count > 0`.

Retry with half as many samples until a config matches, down to 0.
`sample_count: 1`, the default, still asks for 1 sample first, so
apps that don't ask for MSAA get the same config as before.

Verified on the Android emulator (API 34, `-gpu auto`): 4 and 2
samples match nothing, 1 matches, and the app starts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

0