Skip to content

wgpu: fix the crash on Wayland sessions - #70

Open
alpakaDurumi wants to merge 1 commit into
thorvg:mainfrom
alpakaDurumi:wgpu/fix-crash-on-wayland
Open

wgpu: fix the crash on Wayland sessions#70
alpakaDurumi wants to merge 1 commit into
thorvg:mainfrom
alpakaDurumi:wgpu/fix-crash-on-wayland

Conversation

@alpakaDurumi

Copy link
Copy Markdown

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() (observed on Arch Linux with sdl2-compat as an SDL3 wrapper).

Check SDL_SysWMinfo.subsystem and set up the surface source from the driver actually in use.

@hermet
hermet requested review from wenjieshen and a lite review from Copilot September 1, 2026 16:08
@hermet hermet added the bug Something isn't working label Sep 1, 2026

Copilot AI 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.

🟡 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 #elif selection with a switch (windowWMInfo.subsystem) to choose the correct WGPUSurfaceSource*.
  • Introduces a union-backed surfaceNativeDesc storage 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.nextInChain is currently set by casting the whole surfaceNativeDesc union to WGPUChainedStruct*. 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.

Comment thread src/Example.h
Comment thread src/Example.h
@alpakaDurumi
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
alpakaDurumi force-pushed the wgpu/fix-crash-on-wayland branch from 2eab7db to 3275a7d Compare September 2, 2026 13:29
@alpakaDurumi
alpakaDurumi marked this pull request as ready for review September 2, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants