From 7a5fea113ec6088135b0b6a0fc4297e0ef362bc5 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 4 Mar 2013 21:25:39 +0100 Subject: [PATCH] Fix crash in flushWindowSystemEvents() in QGuiApplication-cleanup. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Check for existence of QGuiApplication, discard events if it is 0. Change-Id: I04b27679033fb13ef2fa38e39757d89465cba94b Reviewed-by: Shawn Rutledge Reviewed-by: Samuel Rødal --- src/gui/kernel/qwindowsysteminterface.cpp | 10 ++++++++++ src/gui/kernel/qwindowsysteminterface_p.h | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp index 8c5a3bc215..3609d5dce6 100644 --- a/src/gui/kernel/qwindowsysteminterface.cpp +++ b/src/gui/kernel/qwindowsysteminterface.cpp @@ -527,6 +527,16 @@ void QWindowSystemInterface::deferredFlushWindowSystemEvents() void QWindowSystemInterface::flushWindowSystemEvents() { + const int count = QWindowSystemInterfacePrivate::windowSystemEventQueue.count(); + if (!count) + return; + if (!QGuiApplication::instance()) { + qWarning().nospace() + << "QWindowSystemInterface::flushWindowSystemEvents() invoked after " + "QGuiApplication destruction, discarding " << count << " events."; + QWindowSystemInterfacePrivate::windowSystemEventQueue.clear(); + return; + } if (QThread::currentThread() != QGuiApplication::instance()->thread()) { QMutexLocker locker(&QWindowSystemInterfacePrivate::flushEventMutex); QWindowSystemInterfacePrivate::FlushEventsEvent *e = new QWindowSystemInterfacePrivate::FlushEventsEvent(); diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h index 431b2cbe1e..eca559abfa 100644 --- a/src/gui/kernel/qwindowsysteminterface_p.h +++ b/src/gui/kernel/qwindowsysteminterface_p.h @@ -387,9 +387,10 @@ public: mutable QMutex mutex; public: WindowSystemEventList() : impl(), mutex() {} - ~WindowSystemEventList() - { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); } + ~WindowSystemEventList() { clear(); } + void clear() + { const QMutexLocker locker(&mutex); qDeleteAll(impl); impl.clear(); } void prepend(WindowSystemEvent *e) { const QMutexLocker locker(&mutex); impl.prepend(e); } WindowSystemEvent *takeFirstOrReturnNull()