首页 > 解决方案 > 无法读取 null 的属性“requestDevice”

问题描述

我试图在 WebGpu 中渲染 Web GPU 着色器对象

它返回此错误

未捕获(承诺中)类型错误:无法在 cube.html:28 处读取 null 的属性“requestDevice”

这是我的 requestDevice 代码

(async () => {
 

    const [adapter, glslang] = await Promise.all([
        navigator.gpu.requestAdapter(),
        import("https://unpkg.com/@webgpu/glslang@0.0.7/web/glslang.js").then(m => m.default())
    ]);

    const device = await adapter.requestDevice();
    
    const canvas = document.getElementById("webgpu-canvas");
    canvas.width = window.innerWidth;
    canvas.height = window.innerHeight;

});

任何想法来解决这个错误?

标签: javascriptwebgpu

解决方案


在尝试了很多事情之后,我通过在 about:flags 中重新启用 --enable-unsafe-webgpu 标志来修复它!

刷新页面之前工作了几次,但后来停止了......现在似乎很好!


推荐阅读