emscripten-core / emscripten-core/emscripten

emscripten_lazy_load_code causes errors on re-entry

Open
#12,891 3 comments 0 reactions 0 assignees View on GitHub
wontfix
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

([Small repro repo](https://gist.github.com/surma/01ccc19a26752b61b4d41fd137b15146))

I am playing around with `emscripten_lazy_load_code` and I am running into an error.

C++ code:

```c++
void my_other_printf(int param) { printf(">>>>>%d\n", param); }

void my_main(int param) {
if (param < 3) {
printf(">%d\n", param);
} else {
emscripten_lazy_load_code();
my_other_printf(param);
}
}
```

On my page, I am hooking up a button that calls `my_main` with increasing integers. So first click `param=1`, second click `param=2`, etc. Once `param >= 3`, it uses the other code branch that triggers the lazy-loading.

The third click triggers the lazy load and succeeds. The forth click triggers some questionable fetches and errors. The fifth and any subsequent clicks succeed as expected.

![Screen Shot 2020-11-26 at 17 19 31](https://user-images.githubusercontent.com/234957/100378768-a8d16200-300b-11eb-9b09-99880e9b72e3.png)

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.