Skip to content

TypeError: getWasmTableEntry(...) is not a function #2964

Closed

Description

@messense

🐛 Bug

pyodide.asm.js:10 Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.
pyodide.asm.js:10 The cause of the fatal error was:
pyodide.asm.js:10 TypeError: getWasmTableEntry(...) is not a function
    at invoke_ii (pyodide.asm.js:10:1544237)
    at 00bcba5a:0x54516
    at invoke_viiiiiiiiiiiiiii (pyodide.asm.js:10:1548668)
    at 00bcba5a:0x414a2
    at invoke_viii (pyodide.asm.js:10:1545014)
    at 00bcba5a:0x56286
    at method_call_trampoline (pyodide.asm.js:10:216572)
    at pyodide.asm.wasm:0x162162
    at method_call_trampoline (pyodide.asm.js:10:216572)
    at pyodide.asm.wasm:0x126317
API.fatal_error @ pyodide.asm.js:10
Module.callPyObjectKwargs @ pyodide.asm.js:10
Module.callPyObject @ pyodide.asm.js:10
apply @ pyodide.asm.js:10
apply @ pyodide.asm.js:10
runPython @ pyodide.asm.js:10
main @ (index):15
await in main (async)
(anonymous) @ (index):22
pyodide.asm.js:10 Stack (most recent call first):
pyodide.asm.js:10   File "<exec>", line 5 in <module>
pyodide.asm.js:10   File "/lib/python3.10/site-packages/_pyodide/_base.py", line 304 in run
pyodide.asm.js:10   File "/lib/python3.10/site-packages/_pyodide/_base.py", line 435 in eval_code
(index):21 Uncaught (in promise) TypeError: getWasmTableEntry(...) is not a function
    at invoke_ii (pyodide.asm.js:10:1544237)
    at 00bcba5a:0x54516
    at invoke_viiiiiiiiiiiiiii (pyodide.asm.js:10:1548668)
    at 00bcba5a:0x414a2
    at invoke_viii (pyodide.asm.js:10:1545014)
    at 00bcba5a:0x56286
    at method_call_trampoline (pyodide.asm.js:10:216572)
    at pyodide.asm.wasm:0x162162
    at method_call_trampoline (pyodide.asm.js:10:216572)
    at pyodide.asm.wasm:0x126317

To Reproduce

https://github.com/kitao/pyxel/tree/maturin

  • First install the maturin beta version: pip install -U --pre maturin
  • Build with maturin: RUSTUP_TOOLCHAIN=nightly maturin build -o dist --release --target wasm32-unknown-emscripten
  • Run ./scripts/start_server and open http://localhost:8000 in browser, see the error in console.

Expected behavior

No TypeError: getWasmTableEntry(...) is not a function in console.

Environment

  • Pyodide Version: 0.21.0
  • Browser version: 104.0.5112.79
  • Any other relevant information:

Additional context

Activity

  1. added
    bug
    on Aug 13, 2022
  2. messense commented on Aug 13, 2022

    @messense
    ContributorAuthor

    image

    I do see getWasmTableEntry function in minified pyodide.asm.js, kinda odd.

    Further debugging shows that getWasmTableEntry(0) returned null so getWasmTableEntry(0)(a1) throws TypeError: getWasmTableEntry(...) is not a function

    image

    Use a debug build of the wheel shows a different error

    pyodide.asm.js:formatted:3231 TypeError: Cannot read properties of undefined (reading 'apply')
        at stubs.<computed> (pyodide.asm.js:formatted:8037:49)
        at sdl2::video::_$LT$impl$u20$sdl2..sdl..VideoSubsystem$GT$::desktop_display_mode::h4260488f51b53104 (138d923e:0x3a8287)
        at invoke_viii (pyodide.asm.js:formatted:49510:41)
        at _$LT$pyxel..platform_sdl2..PlatformSdl2$u20$as$u20$pyxel..platform..Platform$GT$::new::h2b4331a8480d882d (138d923e:0x230577)
        at pyxel::Pyxel::new::hf0a38d431462844d (138d923e:0x28edcf)
        at pyxel_wrapper::system_wrapper::init::h3708483ad3f6cd52 (138d923e:0x10792e)
        at pyxel_wrapper::system_wrapper::__pyfunction_init::_$u7b$$u7b$closure$u7d$$u7d$::hdacd4ac63436b841 (138d923e:0x1aa522)
        at std::panicking::try::do_call::h0deb1ab2490d9ce2 (138d923e:0xcb16b)
        at invoke_vi (pyodide.asm.js:formatted:49543:41)
        at __rust_try (138d923e:0x8e92e)
    

    Patch https://github.com/kitao/pyxel/blob/30bb7b5e087408ed3737ab1e7e224bf9bb3f789d/crates/pyxel-engine/src/platform_sdl2.rs#L59-L60 to let scale = get_scale(width, height); reverts back to the original TypeError: getWasmTableEntry(...) is not a function error

    image

  3. ryanking13 commented on Aug 13, 2022

    @ryanking13
    Member

    Thanks for the report, @messense. I can reproduce the error.
    For those who want to quickly reproduce the error, here is the wheel of pyxel (compressed due to Github limitation).

    pyxel-1.8.0-cp37-abi3-emscripten_3_1_14_wasm32.zip

  4. hoodmane commented on Aug 13, 2022

    @hoodmane
    Member

    What happens if you build with panic=abort?

  5. messense commented on Aug 13, 2022

    @messense
    ContributorAuthor

    @hoodmane With panic=abort

    TypeError: Cannot read properties of undefined (reading 'apply')
        at stubs.<computed> (pyodide.asm.js:10:253214)
        at 00898aaa:0x2393f
        at method_call_trampoline (pyodide.asm.js:10:216572)
        at pyodide.asm.wasm:0x162162
        at method_call_trampoline (pyodide.asm.js:10:216572)
        at pyodide.asm.wasm:0x126317
        at pyodide.asm.wasm:0x1e246f
        at pyodide.asm.wasm:0x1e00b3
        at pyodide.asm.wasm:0x1da6a5
        at pyodide.asm.wasm:0x1d9a6a
    
  6. hoodmane commented on Aug 13, 2022

    @hoodmane
    Member

    Looks like progress. We should patch library_dylink to report the name of the missing symbols so that we can get better error messages in this case. We can probably contribute such a change to emscripten.

  7. messense commented on Aug 14, 2022

    @messense
    ContributorAuthor

    Add a conditional breakpoint shows that the missing symbols is SDL_GetDesktopDisplayMode, seems like SDL2 isn't properly linked? I don't know much about linking in Emscripten, not sure what went wrong.

  8. km19809 commented on Aug 15, 2022

    @km19809

    I thought the linking error occurred because LLVM version mismatch.
    Emscripten 3.1.14 uses LLVM 15, but rustc 1.65.0-nightly (latest) uses LLVM 14.

    However, when I downgraded pyodide to 0.20.0 and emscripten 2.0.27 (which uses LLVM 14) , it threw the following error:
    image

    So I was not able to find out whether the LLVM version matters.

    To reproduce:

    I built it using RUSTUP_TOOLCHAIN=nightly maturin build -o dist --release --target wasm32-unknown-emscripten -- -C target-feature=+mutable-globals, with rustc 1.65.0-nightly.

    And I used pyodide.loadPackage to load the emscripten wheel. (Due to the limitation of pyodide 0.20.0)

            async function main() {
                let pyodide = await loadPyodide();
                await pyodide.loadPackage(location.href.replace(/\/[^\/]+?\.[^\/]+?$/, '/')+"pyxel-1.8.0-cp37-abi3-emscripten_2_0_27_wasm32.whl");
                await pyodide.runPython(`
                    import pyxel
                    print("PYXEL_VERSION = ", pyxel.PYXEL_VERSION)
                    print("KEY_BACKSPACE = ", pyxel.KEY_BACKSPACE)
                    pyxel.init(100, 100)
                `);
            }
            main();
        
  9. hoodmane commented on Aug 15, 2022

    @hoodmane
    Member

    Probably the issue is that we aren't linking SDL into Pyodide?

  10. messense commented on Aug 15, 2022

    @messense
    ContributorAuthor

    Probably the issue is that we aren't linking SDL into Pyodide?

    OK, I've just read the Dynamic Linking documentation of Emscripten now. In this case I think Pyodide is the main module and pyxel is the side module, because only main module has system libraries linked in, in order to make it work we need to link SDL into Pyodide, right?

    @hoodmane Do we have an easy way to do a customized Pyodide build with SDL2 linked in?

  11. km19809 commented on Aug 15, 2022

    @km19809

    There is a closed issue that seems related to this.
    #1657 (comment)

    Should I rebuild pyodide with modified MAIN_MODULE_LDFLAGS in Makefile.envs?

  12. messense commented on Aug 15, 2022

    @messense
    ContributorAuthor

    I guess another option is to statically link SDL2 in pyxel? See https://github.com/Rust-SDL2/rust-sdl2#bundled-feature and https://github.com/Rust-SDL2/rust-sdl2#static-linking-in-linux, I haven't tried so not sure whether it will build or not for wasm32-unknown-emscripten target.

  13. hoodmane commented on Aug 15, 2022

    @hoodmane
    Member

    Should I rebuild pyodide with modified MAIN_MODULE_LDFLAGS in Makefile.envs?

    Yes. You need to add -sUSE_SDL=2 to the MAIN_MODULE_LDFLAGS.

    another option is to statically link SDL2 in pyxel?

    This is not possible because SDL2 is implemented in Javascript and Emscripten does not currently allow dynamically loading Javascript.

  14. km19809 commented on Aug 15, 2022

    @km19809

    I rebuilt pyodide with -sUSE_SDL=2, then the message changed:
    image

    I assumed this is related to a canvas issue(emscripten-ports/SDL2#130),
    so I added a blank canvas with id "canvas":

    <!-- Bootstrap HTML for running the unit tests. -->
    <!DOCTYPE html>
    <html>
      <head>
        <title>pyodide</title>
        <script src="./pyodide.js"></script>
      </head>
      <body>
        <canvas id="canvas"></canvas>
        <script type="text/javascript">
          async function main(){
            const pyodide = await loadPyodide();
            await pyodide.loadPackage("micropip")
            const micropip = pyodide.pyimport("micropip")
            await micropip.install("pyxel-1.8.0-cp37-abi3-emscripten_3_1_14_wasm32.whl")
            await pyodide.runPython(`
                    import pyxel
                    pyxel.init(600,480)
            `)
          }
          main()
        </script>
      </body>
    </html>

    Then the error changed:
    image

    Although it crashes, the initial linking issue seems to be resolved.

  15. messense commented on Aug 15, 2022

    @messense
    ContributorAuthor

    @km19809 Can you upload the built pyodide.js somewhere?

  16. km19809 commented on Aug 15, 2022

    @km19809

    @messense
    Dropbox

    I think this issue is resolved, but I post the link here as a (potential) conclusion.

  17. hoodmane commented on Aug 15, 2022

    @hoodmane
    Member

    I think setting -sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 would fix the most recent error.

    You may also want -sMAX_WEBGL_VERSION=2.

  18. messense commented on Aug 15, 2022

    @messense
    ContributorAuthor

    Thanks for the help!

  19. hoodmane commented on Aug 15, 2022

    @hoodmane
    Member

    Please don't hesitate to open a follow up issue if you can't figure out how to get it working.

  20. km19809 commented on Aug 15, 2022

    @km19809

    I think setting -sGL_WORKAROUND_SAFARI_GETCONTEXT_BUG=0 would fix the most recent error.

    You may also want -sMAX_WEBGL_VERSION=2.

    This resolved SafariWebGL2 issue. (It still crashes though 😂)
    Thank you a lot!

  21. henryiii commented on May 31, 2024

    @henryiii
    Contributor

    Using the new cibuildwheel support, both boost-histogram and iminuit report this error.

  22. hoodmane commented on May 31, 2024

    @hoodmane
    Member

    I can reproduce it, I'll take a look soon =)

  23. added 2 commits that reference this issue on Jun 7, 2024
    fa7dcc3
    af8cf23
  24. ryanking13 commented on Jun 8, 2024

    @ryanking13
    Member

    The problem has to do with dynamic linking of JavaScript symbols.

    Hmm, they use SDL and SDL symbols are splitted into main module and side modules so I guess it is somehow related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions