emscripten-core / emscripten-core/emscripten
emscripten_fetch returns id 0 if not used with EMSCRIPTEN_FETCH_REPLACE
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
Tested with version 3.1.73.
When calling `emscripten_fetch` with any combination of attributes, but **without** using `EMSCRIPTEN_FETCH_REPLACE`, the `emscripten_fetch_t` struct it returns always has the `id` member set to `0`. With `EMSCRIPTEN_FETCH_REPLACE`, these increment normally.
Callbacks receive the correct `id` in all cases, just the struct initially returned by `emscripten_fetch` is wrong.
Minimal example to reproduce:
```cpp
emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
std::strcpy(attr.requestMethod, "GET");
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_REPLACE;
for(unsigned int i{0}; i != 10; ++i} {
emscripten_fetch_t *fetch{emscripten_fetch(&attr, "example.com")};
std::cout << "id: " << fetch->id << std::endl; // incrementing normally: 1, 2, 3, ...
}
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
for(unsigned int i{0}; i != 10; ++i} {
emscripten_fetch_t *fetch{emscripten_fetch(&attr, "example.com")};
std::cout << "id: " << fetch->id << std::endl; // always 0
}
```
Contributor guide
Assessment
This issue has not been assessed yet.