【问题标题】:Error "Cannot set property 'widthNative'" while loading wasm加载 wasm 时出现错误“无法设置属性 'widthNative'”
【发布时间】:2018-10-05 07:59:08
【问题描述】:

我尝试在我的网络画布中流式传输 wasm 的输出。 但是,在加载我的 Wasm 的 Main 函数时,会引发以下异常:

hello.js:10522 exception thrown: TypeError: Cannot set property 'widthNative' of undefined,TypeError: Cannot set property 'widthNative' of undefined
at Object.updateCanvasDimensions (http://192.168.0.109:8080/hello.js:5876:30)
at Object.setCanvasSize (http://192.168.0.109:8080/hello.js:5854:17)
at _emscripten_set_canvas_size (http://192.168.0.109:8080/hello.js:9590:15)
at wasm-function[764]:168
at wasm-function[1034]:1597
at wasm-function[327]:57
at wasm-function[329]:9
at wasm-function[330]:9
at Object.Module._main (http://192.168.0.109:8080/hello.js:10327:75)
at Object.callMain (http://192.168.0.109:8080/hello.js:10502:30)

我已经在生成的 js 文件中识别出负责 esception 的部分代码:

updateCanvasDimensions:function (canvas, wNative, hNative) {
    if (wNative && hNative) {
      canvas.widthNative = wNative;
      canvas.heightNative = hNative;
    } else {
      wNative = canvas.widthNative;
      hNative = canvas.heightNative;
    }

我怀疑编译器 emcc 有问题。 这是我的编译命令行:

emcc -o hello.html hello.c -O3 -s WASM=1 --shell-file html_template/shell_minimal.html -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s NO_EXIT_RUNTIME=1 --embed-file pong.c8 -s EXPORTED_FUNCTIONS=[\"_main\",\"_test_function\"] -s EXTRA_EXPORTED_RUNTIME_METHODS=[\"ccall\"]"

有什么想法吗?非常感谢。

【问题讨论】:

    标签: javascript emscripten webassembly


    【解决方案1】:

    我找到了解决方案。 实际上,需要在主脚本之前分配属性画布(Module.canvas):

    var Module = {
            canvas: (function() {
                var canvas = document.getElementById('canvas');
                return canvas;
                })()
        };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-22
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多