Skip to content

wgpuInstanceCreateSurface fails because document is undefined #20211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Ravbug opened this issue Sep 8, 2023 · 5 comments
Open

wgpuInstanceCreateSurface fails because document is undefined #20211

Ravbug opened this issue Sep 8, 2023 · 5 comments

Comments

@Ravbug
Copy link

Ravbug commented Sep 8, 2023

I am trying to create a Surface from an HTML element:

WGPUSurfaceDescriptorFromCanvasHTMLSelector canvasDesc{
    .chain = {
        .next = nullptr,
        .sType = WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector 
    },
    .selector = "#canvas"
};
WGPUSurfaceDescriptor desc{
    .nextInChain = &canvasDesc.chain,
    .label = "Surface"
};
surface = wgpuInstanceCreateSurface(instance, &desc);

However, this call fails because in calling findCanvasEventTarget it calls findEventTarget, where document is undefined and so returns undefined.

// domElement evaluates to undefined
var domElement = specialHTMLTargets[target] || (typeof document != 'undefined' ? document.querySelector(target) : undefined);

Stack trace and output:
image

Version of emscripten/emsdk:

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.45 (ef3e4e3b044de98e1811546e0bc605c65d3412f4)
clang version 18.0.0 (https://github.com/llvm/llvm-project d1e685df45dc5944b43d2547d0138cd4a3ee4efe)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: C:\Users\Admin\Documents\emsdk\upstream\bin 

Browser version:
Chromium Version 118.0.5987.0 (Developer Build) (64-bit)

@sbc100
Copy link
Collaborator

sbc100 commented Sep 8, 2023

It looks like you are maybe trying to use webgpu from a worker thread? is that correct? Are you starting the application in a worker, or are you attempting to use this API from a pthread perhaps?

@Ravbug
Copy link
Author

Ravbug commented Sep 8, 2023

I'm not using a worker thread, but I am using asyncify. Could that also cause issues?

@sbc100
Copy link
Collaborator

sbc100 commented Sep 8, 2023

If you are not using a worker then how could document not be defined. IIUC its always defined on the main thread.

@Ravbug
Copy link
Author

Ravbug commented Sep 8, 2023

I am not manually creating any worker threads, but I am also using PROXY_TO_PTHREAD. If I remove all pthread-related compile and link flags, then the error does not occur. Is this meant to work with PROXY_TO_PTHREAD?

@sbc100
Copy link
Collaborator

sbc100 commented Sep 8, 2023

I have change that proxies the webgpu calls back to the main thread: #20124. Hopefully once this change lands it will fix your problem.

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

No branches or pull requests

2 participants