From 75c22d459872aca47ac2bb9e0e88d63f4f0b5d38 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 7 Feb 2018 14:08:17 +0100 Subject: QCocoaWindow: be more careful when flushing events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Flushing the QPA event queue is problematic since we can then end up delivering several events to Qt (or the app) at the same time on the call stack. This again can easily leave objects in an inconsistent state if they receive callbacks from subsequent events while being occupied processing the first. This is also what happens in the listed report. A QMenu shows a sub menu when the mouse enters a menu item. The show leads to QPA flushing events, which in some cases also includes flushing another pending move event. The move event is delivered to the same QMenu, which will clear a private variable (currentAction). When the show returns, the state of QMenu has unexpectedly changed, which causes a crash to happen since currentAction is null. This patch will fix the root cause of the problem by stopping QCocoaWindow from flushing user input events when the call location does a flush to deliver geometry events. Task-number: QTBUG-66093 Change-Id: Id277550b0a080ad98c81e8c30dc7098dc73723d5 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/cocoa/qcocoawindow.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index af2931c747..683834c1a0 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1131,7 +1131,7 @@ void QCocoaWindow::handleGeometryChange() // Guard against processing window system events during QWindow::setGeometry // calls, which Qt and Qt applications do not expect. if (!m_inSetGeometry) - QWindowSystemInterface::flushWindowSystemEvents(); + QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); } void QCocoaWindow::handleExposeEvent(const QRegion ®ion) -- cgit v1.2.3