emscripten-core / emscripten-core/emscripten
ASYNCIFY=1 does not work with functions that need to return a value back to JS
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
ASYNCIFY=1 does not work with functions that need to return a value back to JS side, for example `emscripten_request_animation_frame_loop()`.
`a.cpp`
```c++
#include
#include
extern "C" void wgpu_buffer_map_sync(int buffer, int mode, double offset, double size);
EM_BOOL raf(double time, void *userData)
{
EM_ASM(console.log(`rAF at time ${$0}`), time);
// Map a GPU buffer synchronously
wgpu_buffer_map_sync(1,2,3,4);
// Return EM_TRUE to signal we want to keep the rAF loop going on.
return EM_TRUE;
}
int main()
{
emscripten_request_animation_frame_loop(raf, 0);
}
```
`lib_a.js`
```js
mergeInto(LibraryManager.library, {
wgpu_buffer_map_sync__sig: 'viidd',
wgpu_buffer_map_sync__async: true,
wgpu_buffer_map_sync: (i1, i2, d1, d2) => Asyncify.handleAsync(async () => {
await 42;
}),
});
```
```
em++ a.cpp --js-library lib_a.js -sASYNCIFY=1 -o a.html
```
The intent with this program is to have the application render continuously in a rAF loop, and map a WebGPU buffer in each tick of the loop.
However, `wgpu_buffer_map_sync()` ends up returning integer `0` back to caller, and the frame loop will not be set up to continue.
(With brief testing, it seems that maybe `-sASYNCIFY=2` does not have this issue)
I wonder if there is any way to fix the above issue?
Contributor guide
Assessment
This issue has not been assessed yet.