wgpu: fix the crash on Wayland sessions - #70
Open
alpakaDurumi wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fix appears incomplete (similar logic remains in another code path) and the new switch has an unhandled default/invalid-chain scenario that can lead to undefined behavior.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR addresses a WebGPU surface-creation crash on Linux Wayland sessions by selecting the SDL native window handle source based on the runtime SDL_SysWMinfo.subsystem rather than a compile-time #elif chain over SDL_VIDEO_DRIVER_* macros.
Changes:
- Replaces compile-time
#elifselection with aswitch (windowWMInfo.subsystem)to choose the correctWGPUSurfaceSource*. - Introduces a union-backed
surfaceNativeDescstorage to hold the platform-specific WebGPU surface source descriptor.
File summaries
| File | Description |
|---|---|
| src/Example.h | Switches WebGPU surface source selection to runtime SDL subsystem to avoid union misinterpretation on Wayland/X11 dual builds. |
Review details
Suppressed comments (1)
src/Example.h:504
surfaceDesc.nextInChainis currently set by casting the wholesurfaceNativeDescunion toWGPUChainedStruct*. It’s safer and clearer to pass a pointer to the active surface-source struct’s.chain(all union members start at offset 0), avoiding type-punning a union object into an unrelated type.
// create surface
WGPUSurfaceDescriptor surfaceDesc{};
surfaceDesc.nextInChain = (WGPUChainedStruct*)&surfaceNativeDesc;
surfaceDesc.label.data = "The surface";
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
alpakaDurumi
marked this pull request as draft
September 2, 2026 13:17
Each SDL_VIDEO_DRIVER_* macro is defined for every driver SDL was built with, so on Linux X11 and Wayland can be enabled at the same time. The surface source was chosen by an #elif chain on those macros, so a session actually running on Wayland could still be compiled into the X11 branch and set up the wrong surface source. It then read SDL_SysWMinfo.info.x11 out of a union holding Wayland members, handing a wl_display* to Xlib, which crashed in XGetXCBConnection() under wgpuInstanceRequestAdapter(). Check SDL_SysWMinfo.subsystem and set up the surface source from the driver actually in use.
alpakaDurumi
force-pushed
the
wgpu/fix-crash-on-wayland
branch
from
September 2, 2026 13:29
2eab7db to
3275a7d
Compare
alpakaDurumi
marked this pull request as ready for review
September 2, 2026 13:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each
SDL_VIDEO_DRIVER_*macro is defined for every driver SDL was built with, so on Linux X11 and Wayland can be enabled at the same time. The surface source was chosen by an#elifchain on those macros, so a session actually running on Wayland could still be compiled into the X11 branch and set up the wrong surface source. It then readSDL_SysWMinfo.info.x11out of a union holding Wayland members, handing awl_display*to Xlib, which crashed inXGetXCBConnection()underwgpuInstanceRequestAdapter()(observed on Arch Linux with sdl2-compat as an SDL3 wrapper).Check
SDL_SysWMinfo.subsystemand set up the surface source from the driver actually in use.