Fix QApplication autotest crash when running on multiple screens
authorMiikka Heikkinen <miikka.heikkinen@digia.com>
Thu, 1 Mar 2012 11:19:24 +0000 (13:19 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 2 Mar 2012 13:45:23 +0000 (14:45 +0100)
Screens need to be destroyed in reverse order to ensure the primary
screen stays valid when other screens are destroyed.

Task-number: QTBUG-24300
Change-Id: I9d9d710aa67ec045baa8bf292833ffe7d9eea935
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
src/plugins/platforms/cocoa/qcocoaintegration.h
src/plugins/platforms/cocoa/qcocoaintegration.mm
src/plugins/platforms/windows/qwindowsscreen.h
src/plugins/platforms/xcb/qxcbconnection.cpp
tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp

index be06154..5493b21 100644 (file)
@@ -97,6 +97,7 @@ private:
 
     QScopedPointer<QPlatformAccessibility> mAccessibility;
     QScopedPointer<QPlatformTheme> mPlatformTheme;
+    QList<QCocoaScreen *> mScreens;
 };
 
 QT_END_NAMESPACE
index fb8e487..626a7fe 100644 (file)
@@ -134,6 +134,7 @@ QCocoaIntegration::QCocoaIntegration()
     NSArray *screens = [NSScreen screens];
     for (uint i = 0; i < [screens count]; i++) {
         QCocoaScreen *screen = new QCocoaScreen(i);
+        mScreens.append(screen);
         screenAdded(screen);
     }
 
@@ -142,6 +143,11 @@ QCocoaIntegration::QCocoaIntegration()
 QCocoaIntegration::~QCocoaIntegration()
 {
     [[NSApplication sharedApplication] setDelegate: 0];
+
+    // Delete screens in reverse order to avoid crash in case of multiple screens
+    while (!mScreens.isEmpty()) {
+        delete mScreens.takeLast();
+    }
 }
 
 bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) const
index 436cc2c..77a327a 100644 (file)
@@ -115,7 +115,11 @@ public:
 
     QWindowsScreenManager();
 
-    inline void clearScreens() { qDeleteAll(m_screens); m_screens.clear(); }
+    inline void clearScreens() {
+        // Delete screens in reverse order to avoid crash in case of multiple screens
+        while (!m_screens.isEmpty())
+            delete m_screens.takeLast();
+    }
 
     void handleScreenChanges();
     bool handleDisplayChange(WPARAM wParam, LPARAM lParam);
index 04c43eb..9a68d85 100644 (file)
@@ -191,7 +191,9 @@ QXcbConnection::~QXcbConnection()
 {
     delete m_clipboard;
 
-    qDeleteAll(m_screens);
+    // Delete screens in reverse order to avoid crash in case of multiple screens
+    while (!m_screens.isEmpty())
+        delete m_screens.takeLast();
 
 #ifdef XCB_USE_XINPUT2_MAEMO
     finalizeXInput2();
index 98872cb..9bbb6aa 100644 (file)
@@ -605,9 +605,6 @@ public slots:
 
 void tst_QApplication::quitOnLastWindowClosed()
 {
-#ifdef Q_OS_WIN32
-    QSKIP("This test crashes on Windows. Remove skip once the issue causing the crash is fixed (QTBUG-24300).");
-#endif
 #ifndef Q_OS_MAC
     // Test hangs on Mac OS X, see QTBUG-24319
     {