Error: WebGPU canvas selector with vtkWebAssemblyHardwareWindow fails for the official Geometry Viewer Emscripten Example

Hi,

I have noticed that the WebGPU canvas selector for the official example Geometry Viewer fails as it defaults to the default canvas selection id canvas instead of vtk-3d-canvas.

These are the commands I have used to build with the latest docker image as well as the official 9.6.0 tag.

docker run --rm -it `
  -v"$PWD":/work kitware/vtk-wasm-sdk:latest `
  emcmake cmake -GNinja -S /work -B /work/build -DVTK_DIR=/VTK-install/Release/wasm32/lib/cmake/vtk

# Build
docker run --rm -it `
  -v"$PWD":/work kitware/vtk-wasm-sdk:latest `
  cmake --build /work/build

The build will be successful however the WebGPU backend will fail for the latest images.

I have noticed a new class vtkWebAssemblyHardwareWindow is adopted in the latest commits and the class is changed from vtkWebAssemblyWebGPURenderWidow for canvas selection.

  if (auto wasmHardwareWindow =
       vtkWebAssemblyHardwareWindow::SafeDownCast(this->P->Window->GetHardwareWindow()))
  {
    wasmHardwareWindow->SetCanvasSelector("#vtk-3d-canvas");
  } 

The cast is failing and the canvas selection is not set for the WebGPU backend.

Hi @RaMmer

Thank you for posting this here. Let me look into it and get back.

Here are my findings:

check out VTK v9.6.0, build GeometryViewer with vtk-wasm-sdk:9.6.0 image - OK
check out VTK master, build GeometryViewer with vtk-wasm-sdk:latest image - not OK

Uncaught TypeError: Cannot read properties of null (reading 'getContext')
    at _wgpuInstanceCreateSurface (http://localhost:8001/GeometryViewer.js:11105:24)
    at GeometryViewer.wasm.vtkWebGPURenderWindow::CreateSurface() (http://localhost:8001/GeometryViewer.wasm:wasm-function[10569]:0x31ae8b)
    at GeometryViewer.wasm.vtkWebGPURenderWindow::Initialize() (http://localhost:8001/GeometryViewer.wasm:wasm-function[10570]:0x31af74)
    at GeometryViewer.wasm.vtkWebGPURenderWindow::Start() (http://localhost:8001/GeometryViewer.wasm:wasm-function[10605]:0x325768)
    at GeometryViewer.wasm.vtkWebAssemblyRenderWindowInteractor::Initialize() (http://localhost:8001/GeometryViewer.wasm:wasm-function[10953]:0x33e937)
    at GeometryViewer.wasm.vtkRenderWindow::Render() (http://localhost:8001/GeometryViewer.wasm:wasm-function[14323]:0x48806a)
    at GeometryViewer.wasm.vtkWebGPURenderWindow::Render() (http://localhost:8001/GeometryViewer.wasm:wasm-function[10581]:0x31fabe)
    at GeometryViewer.wasm.GeometryViewer::Render() (http://localhost:8001/GeometryViewer.wasm:wasm-function[467]:0x2db23)
    at GeometryViewer.wasm.emscripten::internal::MethodInvoker<emscripten::internal::rvp::default_tag, void (GeometryViewer::*)(), void, GeometryViewer*>::invoke(void (GeometryViewer::* const&)(), GeometryViewer*) (http://localhost:8001/GeometryViewer.wasm:wasm-function[736]:0x361d2)
    at async main (http://localhost:8001/index.js:340:3)

I have a fix in https://gitlab.kitware.com/vtk/vtk/-/merge_requests/12985

The example is now fixed in master branch. Please sync your VTK clone, and try again with the vtk-wasm-sdk:latest image.

1 Like

Thank You!