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 <lorn.potter@gmail.com>
This commit is contained in:
Morten Johan Sørvig 2021-09-30 15:01:14 +02:00
parent 8652f4766b
commit 9875869d31

View File

@ -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<void(void)> fn)
{
static auto trampoline = [](void *context) {
namespace {
void trampoline(void *context) {
std::function<void(void)> *fn = reinterpret_cast<std::function<void(void)> *>(context);
(*fn)();
delete fn;
};
}
}
// Runs a function on the main thread
void QEventDispatcherWasm::runOnMainThread(std::function<void(void)> fn)
{
void *context = new std::function<void(void)>(fn);
emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast<void *>(&trampoline), context);
emscripten_async_run_in_main_runtime_thread_(EM_FUNC_SIG_VI, reinterpret_cast<void *>(trampoline), context);
}
#endif