Skip to content

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

Open
robertpakalns wants to merge 1 commit intogfx-rs:trunkfrom
robertpakalns:webgl-fix
Open

fix: provide default display handle for web canvas surface targets#9476
robertpakalns wants to merge 1 commit intogfx-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

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