diff options
author | Mikolaj Boc <[email protected]> | 2022-12-15 13:24:19 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2022-12-16 19:51:21 +0000 |
commit | 6415730b98ac41507222b9ebbdb61d8f08759d1c (patch) | |
tree | 4aeee7c889bc8f63580821aabeff97c32b2dc3cc | |
parent | 7f6e5d47482ffffed0237bde0960757d57bcbdcf (diff) |
Fix event dispatching on WASM
1) Check only for the events that the dispatcher is able to process,
otherwise it enters an endless loop
2) Take care to run the correct wake up callback with
Asyncify.handleSleep
Fixes: QTBUG-109066
Change-Id: I10d29d18962c3e438e56712e1f43ecadedb6205c
Reviewed-by: Morten Johan Sørvig <[email protected]>
(cherry picked from commit 8f04c50cffe5d6b3963a29715b2dd2d37269d5de)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_wasm.cpp | 21 | ||||
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_wasm_p.h | 3 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmeventdispatcher.cpp | 4 | ||||
-rw-r--r-- | src/plugins/platforms/wasm/qwasmeventdispatcher.h | 1 |
4 files changed, 23 insertions, 6 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 23f218c4a00..23d558a61bb 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -41,9 +41,12 @@ static bool useAsyncify() } EM_JS(void, qt_asyncify_suspend_js, (), { + if (Module.qtSuspendId === undefined) + Module.qtSuspendId = 0; let sleepFn = (wakeUp) => { Module.qtAsyncifyWakeUp = wakeUp; }; + ++Module.qtSuspendId; return Asyncify.handleSleep(sleepFn); }); @@ -52,10 +55,16 @@ EM_JS(void, qt_asyncify_resume_js, (), { if (wakeUp == undefined) return; Module.qtAsyncifyWakeUp = undefined; + const suspendId = Module.qtSuspendId; // Delayed wakeup with zero-timer. Workaround/fix for // https://github.com/emscripten-core/emscripten/issues/10515 - setTimeout(wakeUp); + setTimeout(() => { + // Another suspend occurred while the timeout was in queue. + if (Module.qtSuspendId !== suspendId) + return; + wakeUp(); + }); }); #else @@ -200,7 +209,7 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) { emit awake(); - bool hasPendingEvents = qGlobalPostedEventsCount() > 0; + bool hasPendingEvents = hasWindowSystemEvents(); qCDebug(lcEventDispatcher) << "QEventDispatcherWasm::processEvents flags" << flags << "pending events" << hasPendingEvents; @@ -212,8 +221,6 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) handleApplicationExec(); } - hasPendingEvents = qGlobalPostedEventsCount() > 0; - if (!hasPendingEvents && (flags & QEventLoop::WaitForMoreEvents)) wait(); @@ -227,7 +234,7 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) processTimers(); } - hasPendingEvents = qGlobalPostedEventsCount() > 0; + hasPendingEvents = hasWindowSystemEvents(); QCoreApplication::sendPostedEvents(); processWindowSystemEvents(flags); return hasPendingEvents; @@ -238,6 +245,10 @@ void QEventDispatcherWasm::processWindowSystemEvents(QEventLoop::ProcessEventsFl Q_UNUSED(flags); } +bool QEventDispatcherWasm::hasWindowSystemEvents() { + return false; +} + void QEventDispatcherWasm::registerSocketNotifier(QSocketNotifier *notifier) { LOCK_GUARD(g_staticDataMutex); diff --git a/src/corelib/kernel/qeventdispatcher_wasm_p.h b/src/corelib/kernel/qeventdispatcher_wasm_p.h index b6de4187f4f..3c211b30528 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm_p.h +++ b/src/corelib/kernel/qeventdispatcher_wasm_p.h @@ -52,7 +52,8 @@ public: static void socketSelect(int timeout, int socket, bool waitForRead, bool waitForWrite, bool *selectForRead, bool *selectForWrite, bool *socketDisconnect); - protected: +protected: + virtual bool hasWindowSystemEvents(); virtual void processWindowSystemEvents(QEventLoop::ProcessEventsFlags flags); private: diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp index 2fd1a304011..f48bcb6314b 100644 --- a/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp +++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.cpp @@ -14,4 +14,8 @@ void QWasmEventDispatcher::processWindowSystemEvents(QEventLoop::ProcessEventsFl QWindowSystemInterface::sendWindowSystemEvents(flags); } +bool QWasmEventDispatcher::hasWindowSystemEvents() { + return QWindowSystemInterface::windowSystemEventsQueued(); +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/wasm/qwasmeventdispatcher.h b/src/plugins/platforms/wasm/qwasmeventdispatcher.h index a28fa7263bc..5b9b08cba3d 100644 --- a/src/plugins/platforms/wasm/qwasmeventdispatcher.h +++ b/src/plugins/platforms/wasm/qwasmeventdispatcher.h @@ -12,6 +12,7 @@ class QWasmEventDispatcher : public QEventDispatcherWasm { protected: void processWindowSystemEvents(QEventLoop::ProcessEventsFlags flags) override; + bool hasWindowSystemEvents() override; }; QT_END_NAMESPACE |