From 0a8a4698d65d1a579edfa29d6a62644eedd64a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Fri, 8 Oct 2021 11:03:44 +0200 Subject: wasm: fix native timer update for the no-timer case QTimerInfoList::timerWait() does not update the timespec out argument if there are no active timers, which caused the current code to calculate an arbitrary toWaitDuration. Instead use the timerWait() return value, and clear any native timers if there are no active Qt timers. Pick-to: 6.2 Change-Id: I7d5ec4c2930000bece6f6ea6c63e76f4df543b04 Reviewed-by: Lorn Potter --- src/corelib/kernel/qeventdispatcher_wasm.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qeventdispatcher_wasm.cpp b/src/corelib/kernel/qeventdispatcher_wasm.cpp index 15ada58aad..b499cf91fe 100644 --- a/src/corelib/kernel/qeventdispatcher_wasm.cpp +++ b/src/corelib/kernel/qeventdispatcher_wasm.cpp @@ -480,14 +480,22 @@ void QEventDispatcherWasm::updateNativeTimer() return ts.tv_sec * 1000 + ts.tv_nsec / (1000 * 1000); }; timespec toWait; - m_timerInfo->timerWait(toWait); + bool hasTimer = m_timerInfo->timerWait(toWait); uint64_t currentTime = timespecToNanosec(m_timerInfo->currentTime); uint64_t toWaitDuration = timespecToNanosec(toWait); uint64_t newTargetTime = currentTime + toWaitDuration; - auto maintainNativeTimer = [this, toWaitDuration, newTargetTime]() { + auto maintainNativeTimer = [this, hasTimer, toWaitDuration, newTargetTime]() { Q_ASSERT(emscripten_is_main_runtime_thread()); + if (!hasTimer) { + if (m_timerId > 0) { + emscripten_clear_timeout(m_timerId); + m_timerId = 0; + } + return; + } + if (m_timerTargetTime != 0 && newTargetTime >= m_timerTargetTime) return; // existing timer is good -- cgit v1.2.3