From 9875869d3174cf0f15ebfccac427ade3cb01e046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 30 Sep 2021 15:01:14 +0200 Subject: [PATCH] wasm: fix runOnMainThread() Calling emscripten_async_run_in_main_runtime_thread_() with a pointer to a static lambda was too clever, use an anonymous function as callback instead. Pick-to: 6.2 Task-number: QTBUG-94344 Change-Id: I2d8a8b0ffc2dd1d02018aa5902550216d00f641d Reviewed-by: Lorn Potter --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index f5c2802aa6..c0d753c594 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -567,16 +567,20 @@ void QEventDispatcherWasm::callProcessTimers(void *context) } #if QT_CONFIG(thread) -// Runs a function on the main thread -void QEventDispatcherWasm::runOnMainThread(std::function fn) -{ - static auto trampoline = [](void *context) { + +namespace { + void trampoline(void *context) { std::function *fn = reinterpret_cast *>(context); (*fn)(); delete fn; - }; + } +} + +// Runs a function on the main thread +void QEventDispatcherWasm::runOnMainThread(std::function fn) +{ void *context = new std::function(fn); - emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast(&trampoline), context); + emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast(trampoline), context); } #endif