Skip to content

wgpu calls createBuffer on an undefined from a worker thread on Wasm #2884

Closed
@ghost

Description

Description
wgpu attempts to execute the createBuffer method on an undefined when running in a worker thread on the target wasm32-unknown-unknown. The instance, adapter, surface, and device were created on the main thread.

Repro steps
A runnable example is here, the source code for which is here; see wasm.rs and core/src/lib.rs. More generic instructions are described below.

  1. Create a new Rust crate targeting wasm32-unknown-unknown.
  2. Export a main function using #[wasm_bindgen].
  3. In main, create a wgpu instance, adapter, device, and surface.
  4. Create a new thread (e.g., using wasm_thread) in which a vertex buffer is created and initialized with the device returned by wgpu.
  5. Observe the error.

Expected vs observed behavior
I expect the vertex buffer creation to be successful, after which render passes would occur, the command queue would be submitted, and the surface frame would ultimately be presented.

Instead, I observe that attempting to create the vertex buffer from a worker thread crashes the Wasm process.

Extra materials
On Microsoft Edge (Chromium-based), I receive the following error:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'createBuffer')

On Firefox, I receive the following error:
TypeError: can't access property "createBuffer", getObject(...) is undefined

Platform
Windows 11. wgpu 0.13 (latest minor release). naga 0.9.

Metadata

Metadata

Assignees

No one assigned

    Labels

    backend: webgpuIssues with direct interface with WebGPUtype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions