Fix lambda capturing by refrence, since pointers go out of the function scope, it becomes invalid

This commit is contained in:
msqr1
2024-01-31 11:00:51 -08:00
parent f7acda0006
commit 94a8a68170
2 changed files with 32 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ void throwJS(const char* msg, bool err) {
void fireEv(const char *type, const char *content, int index) { void fireEv(const char *type, const char *content, int index) {
static ProxyingQueue pq{}; static ProxyingQueue pq{};
static pthread_t selfTID{pthread_self()}; static pthread_t selfTID{pthread_self()};
static auto proxy{[&](){ static auto proxy{[index, type, content](){
EM_ASM({ EM_ASM({
console.log(objs[$0]); console.log(objs[$0]);
objs[$0].dispatchEvent(new CustomEvent(UTF8ToString($1), {"detail" : UTF8ToString($2)})) objs[$0].dispatchEvent(new CustomEvent(UTF8ToString($1), {"detail" : UTF8ToString($2)}))
@@ -29,9 +29,7 @@ int main() {
//vosk_set_log_level(-1); //vosk_set_log_level(-1);
std::thread t{[](){ std::thread t{[](){
wasmfs_create_directory("/opfs",0777,wasmfs_create_opfs_backend()); wasmfs_create_directory("/opfs",0777,wasmfs_create_opfs_backend());
fireEv("_ev", "test", 0);
}}; }};
t.detach(); t.detach();
fireEv("_ev", "test event", 0);
emscripten_exit_with_live_runtime(); emscripten_exit_with_live_runtime();
} }

File diff suppressed because one or more lines are too long