Web backend crashes when initialized within a worker #1986
Labels
area: correctness
We're behaving incorrectly
help required
We need community help to make this happen.
type: enhancement
New feature or request
Description
The web backend uses
web_sys::window
to obtain a handle to the globalNavigator
object. This does not work when called from a worker scope since there is nowindow
global variable nor aWindow
interface.Repro steps
Create a
Worker
that executes a Rust program compiled to WebAssembly callingwgpu::Instance::new
. Unfortunately I don't have a minimal repro available at the moment.Expected vs observed behavior
Observed behavior: the web backend tries to obtain a handle to the
window
object and performs aninstanceof
check against theWindow
interface, which does not exist in the worker scope. This results in an error:Expected behavior:
In a worker scope, a
web_sys::WorkerGlobalScope
could be used instead to obtain theNavigator
handle, but this might be tricky in practice (rustwasm/wasm-bindgen#1046). Since the program will crash and not returnNone
whenwindow
is not available, it is not enough to useOption::or
to fall back to, say,web_sys::global()
. Based on rustwasm/wasm-bindgen#1982 (comment), this is a problem with otherweb_sys
consumers too and might require some glue code like this.Platform
wgpu
version: masterThe text was updated successfully, but these errors were encountered: