surface reconstruction in javascript

After looking at the links you refer to, that it is a bug in Emscripten. Even if they fix the bugs, I am curious if running the wasm code in a new thread, which is required for synchronous fetch, will cause errors with VTK and OpenGL thread safety?

right, when asynchronous fetching used, how can I get access to the content of the file in a variable that I want to use? fetch->data is accessible in downloadSucceeded, but how can I get access to that in main?

regarding to your question, as API page suggests, I guess synchronous fetch operation is available in both main thread and pthreads with --proxy-to-worker + -s USE_PTHREADS=1 flags.

I call emsripten_fetch from a member function of my class (SwisVtkRadarWindow). I assign the reference of SwisVtkRadarWindow to the fetch attribute called “userData” by using the “this” keyword.

emscripten_fetch_attr_t attr;
emscripten_fetch_attr_init(&attr);
strcpy(attr.requestMethod, “GET”);
attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
attr.userData = this;
attr.onsuccess = downloadSucceeded;
emscripten_fetch(&attr, path.c_str());

Then in the downloadSucceeded callback I use a static cast to get my class from userData and process the data.

void downloadSucceeded(emscripten_fetch_t* fetch) {

while (fetch->readyState != 4)
{
std::cout << “Waiting For Download To Complete.” << std::endl;
}

std::cout << "Finished downloading " << fetch->numBytes << " bytes, and " << fetch->totalBytes << " total bytes from URL " << fetch->url << std::endl;
// The data is now available at fetch->data[0] through fetch->data[fetch->numBytes-1];
std::vector data(fetch->numBytes, 0);
memcpy(data.data(), fetch->data, fetch->numBytes);
emscripten_fetch_close(fetch); // Free data associated with the fetch.

auto radwin = static_cast<SwisVtkRadarWindow*>(fetch->userData);
radwin->DownloadSuccess(data);

}

Regarding the Emscripten compiler flags “–proxy-to-worker + -s USE_PTHREADS=1”. When I tried this I was getting compile errors saying I can’t use --proxy-to-worker flags with USE_PTHREADS=1, which conflicts with the documentation.

2 Likes