godotengine / godotengine/godot

Switching between thread modes in GDExtension web exports fails to update .wasm file, causing export errors

Open
#95,077 6 comments 1 reaction 0 assignees View on GitHub
bug needs testing platform:web topic:gdextension topic:platforms
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible in Godot 4.3.rc2
- Reproducible in Godot 4.3.rc1

### System information

- Windows 10.0.22621 - Vulkan (Forward+)

### Issue Description
When exporting a GDExtension game to the web, the process fails when switching between thread support modes (single-threaded and multithreaded). The first export works correctly, but subsequent exports with a different thread mode result in errors, indicating that the editor may not be updating the `.wasm` file appropriately.

**Configuration:**
The following configuration is used in the `.gdextension` file:
```gdscript
web.debug.threads.wasm32 = "res://bin/libturbo_pancake.web.template_debug.wasm32.wasm"
web.release.threads.wasm32 = "res://bin/libturbo_pancake.web.template_release.wasm32.wasm"
web.debug.wasm32 = "res://bin/libturbo_pancake.web.template_debug.wasm32.nothreads.wasm"
web.release.wasm32 = "res://bin/libturbo_pancake.web.template_release.wasm32.nothreads.wasm"
```

**Behavior:**
- **Initial Export (Multithreaded/Single-threaded)**: Works as expected.
- **Switching Thread Mode**: The subsequent export fails with one of the following errors:
- Single-threaded to multithreaded:
```
Uncaught (in promise) LinkError: import object field 'emscripten_webgl_make_context_current_calling_thread' is not a Function
```
- Multithreaded to single-threaded:
```
Uncaught (in promise) LinkError: imported shared memory but unshared required
```

### Additional Notes
In Godot 4.3.rc2, changing thread support now only takes effect after reloading the project. This behavior allows the game, for instance, to export correctly in single-threaded mode, even if thread support is toggled on or off afterward. In this case, to export the game in multithreaded mode, thread support must be enabled, the project reloaded, and then reexported and ran in the browser. Any other sequence of actions results in one of the errors mentioned above.

### Steps to reproduce
I included the binaries for the web and for windows in the MRE. If you're on another platform, please initialize the godot-cpp submodule and use scons to generate the binaries for your OS before opening the project.

1. Export the project in the desired thread mode (multithreaded or single-threaded). This initial export should work correctly.
2. Change the thread mode (e.g., from multithreaded to single-threaded) and attempt to run the project in the browser. This will likely fail, resulting in one of the errors mentioned above.
3. Attempt to re-export the project without changing any settings. This export will also likely fail.
4. Reload the project in Godot, ensuring that the thread mode setting is unchanged.
5. Re-export the project again without switching thread modes. This time, the export should work as expected.
6. You should see the following scene on the browser or locally:

![image](https://github.com/user-attachments/assets/00ee9528-bbee-454d-903d-777d1c674be7)

### Minimal reproduction project (MRP)

[MRE_export_bug.zip](https://github.com/user-attachments/files/16473522/MRE_export_bug.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.