Skip to content

fix: provide default display handle for web canvas surface targets - #9476

Merged
andyleiserson merged 2 commits into
gfx-rs:trunkfrom
robertpakalns:webgl-fix
May 13, 2026
Merged

fix: provide default display handle for web canvas surface targets#9476
andyleiserson merged 2 commits into
gfx-rs:trunkfrom
robertpakalns:webgl-fix

Conversation

@robertpakalns

Copy link
Copy Markdown
Contributor

Description
Since wgpu version 29, creating a surface from a web canvas using Instance::create_surface with SurfaceTarget::Canvas or SurfaceTarget::OffscreenCanvas fails with CreateSurfaceError::MismatchingDisplayHandle.

This occurs because both SurfaceTarget::Canvas and SurfaceTarget::OffscreenCanvas set raw_display_handle: None. However, in wgpu_core::instance::Instance::create_surface, there is a requirement that either instance_display_handle or display_handle must be present. Since raw_display_handle is always None, it always matches the (None, None) => return Err(CreateSurfaceError::MissingDisplayHandle) arm.

Note: this change does not affect the examples (examples/features) because it utilizes winit which provides a valid RawDisplayHandle when creating windows (including web canvases) and which never hits the (None, None) case.

Testing
Tested in browser using:

 let surface = instance
        .create_surface(SurfaceTarget::Canvas(canvas.clone()))
        .unwrap();

Squash or Rebase?
Squash

@inner-daemons inner-daemons left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cwfitzgerald cwfitzgerald self-assigned this May 6, 2026
@inner-daemons
inner-daemons self-requested a review May 6, 2026 15:22
@inner-daemons

Copy link
Copy Markdown
Collaborator

@cwfitzgerald Can you rerun the CI

@inner-daemons inner-daemons left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine

@andyleiserson andyleiserson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like we may have a test coverage gap, but since this is a regression I won't block on that.

@andyleiserson
andyleiserson merged commit ecbed8b into gfx-rs:trunk May 13, 2026
58 checks passed
@torokati44

torokati44 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

I assume, this is also something that won't be backported to 29.x, so we'd have to skip straight to 30 with ruffle-rs/ruffle#24229?

@cwfitzgerald

Copy link
Copy Markdown
Member

Correct, I don't think this was ever backported

@torokati44

Copy link
Copy Markdown
Contributor

Alright, anyway, I think it's possible to workaround at least.

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.

5 participants