Skip to content
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

Web export with gdextension not working on 4.3 if threads/nothreads variants are mismatched #94537

Open
cosformula opened this issue Jul 19, 2024 · 9 comments

Comments

@cosformula
Copy link
Contributor

Tested versions

  • Reproducible on 4.3.dev6 ~ 4.3.beta3
  • Not Reproducible on 4.2.2 stable

System information

Confirmed on MacOS and Windows

Issue description

Web export with gdextension not working on 4.3 dev6 ~ 4.3.beta3.
Empty project with gdextension support flag on works well, but add a gdextention (I use debug draw 3d, but my own gdextention not working too) addon to the project cause problem, and console says:

LinkError: WebAssembly.instantiate(): Import #62 "env" "memory": mismatch in shared state of memory, declared = 1, imported = 0
image

Steps to reproduce

Download MRP, run in broswer.

Minimal reproduction project (MRP)

gdextention test.zip

@akien-mga
Copy link
Member

Which Emscripten version did you use to compile the GDExtension?

@akien-mga akien-mga added this to the 4.3 milestone Jul 19, 2024
@cosformula
Copy link
Contributor Author

cosformula commented Jul 19, 2024

Which Emscripten version did you use to compile the GDExtension?您使用哪个 Emscripten 版本来编译 GDExtension?

I use 3.1.62.

emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.62-git
clang version 19.0.0git
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/emscripten/3.1.62/libexec/llvm/bin

@akien-mga
Copy link
Member

I can reproduce the issue with the MRP on Firefox with 4.3.beta3, with these errors:

Uncaught (in promise) LinkError: imported function 'env._ZNSt3__26chrono12steady_clock3nowEv' signature mismatch
still waiting on run dependencies: [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
dependency: loadDylibs [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
(end of list) [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
still waiting on run dependencies: [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
dependency: loadDylibs [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
(end of list) [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
still waiting on run dependencies: [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
dependency: loadDylibs [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
(end of list) [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
still waiting on run dependencies: [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
dependency: loadDylibs [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)
(end of list)

Worth noting that the addons includes prebuilt binaries in the git repo. If you're using those instead of compiling your own, then they might not have been compiled with Emscripten 3.1.62, but instead with whichever version @DmitriySalnikov used for the 1.4.2 release. I tested updating to 1.4.3 and it still has the same issue.

One should test with a custom built extension using Emscripten 3.1.62 (like 4.3.beta3) or 3.1.63 (regression fix release, which we'll use for 4.3.rc1).

@DmitriySalnikov
Copy link
Contributor

but instead with whichever version @DmitriySalnikov used for the 1.4.2 release

3.1.39 as mentioned here.

And I finally found what the problem was!
I even managed to launch the project in Firefox. (thanks to the emscripten update?)

image

image

LinkError: WebAssembly.instantiate(): Import #62 "env" "memory": mismatch in shared state of memory, declared = 1, imported = 0

The mismatch between shared and non-shared memory directly depends on threads support.

image

I can reproduce the issue with the MRP on Firefox with 4.3.beta3, with these errors:

Uncaught (in promise) LinkError: imported function 'env._ZNSt3__26chrono12steady_clock3nowEv' signature mismatch
still waiting on run dependencies: [tmp_js_export.js:46811:18](http://localhost:8060/tmp_js_export.js)

Yes, for some reason it is not possible to use std::chrono in my module and I had to switch to using Time::. I have not been able to solve this problem yet.
It seems that the standard libraries are not included in the SIDE_MODULE.

Here you can download .gdextension_libs with new libraries. And here Is an updated .gdextension.
These libraries should still be supported starting with godot 4.2.

@cosformula
Copy link
Contributor Author

Thanks to @DmitriySalnikov. On 4.3.beta3, I'm able to fixed this issue by building gdextensions using threads=no|yes and edit the .gdextension file like below:

...
web.wasm32.nothreads = "res://addons/xxx/bin/libxxx.web.template_debug.wasm32.nothreads.wasm"
web.wasm32 = "res://addons/xr/bin/libxxx.web.template_debug.wasm32.wasm"
...

Maybe we should add this sections to the gdextension tutorial?

@akien-mga akien-mga changed the title Web export with gdextension not working on 4.3 Web export with gdextension not working on 4.3 if threads/nothreads variants are mismatched Jul 22, 2024
@clayjohn clayjohn modified the milestones: 4.3, 4.x Jul 24, 2024
@GeTechG
Copy link

GeTechG commented Aug 17, 2024

I got a similar problem with the same message when running on android, but I was using the official build without multithreading and gdextension.

@Nihlus
Copy link

Nihlus commented Sep 1, 2024

@DmitriySalnikov Did you ever figure out the issue with using Chrono? I'm seeing the same problem along with a mismatched signature on env.strtoll, which is blocking my extension from working with web exports at the moment. I've built with emscripten 3.1.64 to match Godot, but it doesn't appear to make a difference.

@DmitriySalnikov
Copy link
Contributor

@DmitriySalnikov Did you ever figure out the issue with using Chrono?

I tried a few more times, but couldn't solve the problem. So the easiest way is to start using the Godot API.
Perhaps someone with more experience with emscripten can tell us.

@Nihlus
Copy link

Nihlus commented Sep 2, 2024 via email

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

No branches or pull requests

8 participants