From d0c92821af188f49c8b53b86f0b0816c2b9886b2 Mon Sep 17 00:00:00 2001 From: Mikolaj Boc Date: Wed, 9 Aug 2023 15:36:37 +0200 Subject: [PATCH] Do not call processEvents async with JSPI enabled on WASM MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With JSPI, the main dispatcher loop is not exited and processEvents should not be called, as events will get processed after the thread has been unsuspended. processEvents posted with emscripten_async_call causes stack corruption. Fixes: QTBUG-115959 Change-Id: Ibccccbf54f18df2d03f0c5e817c3a7102e96c9ed Reviewed-by: Edward Welbourne Reviewed-by: Morten Johan Sørvig --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 00f3f97ee8..ce245a75a1 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -420,7 +420,9 @@ void QEventDispatcherWasm::wakeUp() // event loop. Make sure the thread is unblocked or make it // process events. bool wasBlocked = wakeEventDispatcherThread(); - if (!wasBlocked && isMainThreadEventDispatcher()) { + // JSPI does not need a scheduled call to processPostedEvents, as the stack is not unwound + // at startup. + if (!qstdweb::haveJspi() && !wasBlocked && isMainThreadEventDispatcher()) { { LOCK_GUARD(m_mutex); if (m_pendingProcessEvents)