From ee72e23897c71ebf79803eb5f1abd0b8410e1951 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Wed, 28 Jun 2023 13:53:24 +0200 Subject: [PATCH] wasm: don't use on qGlobalPostedEventsCount() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no guarantee that it will return 0 after one call to sendPostedEvents(), since more events may have been posted during that call. This can in turn cause infinite looping since the wait() isn't called. Move sendPostedEvents to the top of processEvents() to make sure we send events before waiting, in line with the implementation for the other event dispatchers. Fixes: QTBUG-112893 Change-Id: Iba7d87cf1c08cd302884782cb135d758afeb9e4b Reviewed-by: Morten Johan Sørvig (cherry picked from commit 9c9aca3b4393a1f1c8169c7b811e46ec5de25df9) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 6818a5eab8c..3c38ac94eac 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -212,13 +212,10 @@ bool QEventDispatcherWasm::isValidEventDispatcherPointer(QEventDispatcherWasm *e bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) { + qCDebug(lcEventDispatcher) << "QEventDispatcherWasm::processEvents flags" << flags; + emit awake(); - bool hasPendingEvents = qGlobalPostedEventsCount() > 0; - - qCDebug(lcEventDispatcher) << "QEventDispatcherWasm::processEvents flags" << flags - << "pending events" << hasPendingEvents; - if (isMainThreadEventDispatcher()) { if (flags & QEventLoop::DialogExec) handleDialogExec(); @@ -226,23 +223,23 @@ bool QEventDispatcherWasm::processEvents(QEventLoop::ProcessEventsFlags flags) handleApplicationExec(); } - if (!hasPendingEvents && (flags & QEventLoop::WaitForMoreEvents)) - wait(); + QCoreApplication::sendPostedEvents(); + processWindowSystemEvents(flags); if (m_interrupted) { m_interrupted = false; return false; } + if (flags & QEventLoop::WaitForMoreEvents) + wait(); + if (m_processTimers) { m_processTimers = false; processTimers(); } - QCoreApplication::sendPostedEvents(); - processWindowSystemEvents(flags); - - return qGlobalPostedEventsCount() > 0; + return false; } void QEventDispatcherWasm::processWindowSystemEvents(QEventLoop::ProcessEventsFlags flags)