summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDyami Caliri <dyami@dragonframe.com>2014-03-18 09:03:36 -0700
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-03 11:07:07 +0200
commit2d8b40439da7f3edbed3cfa7354f714686d6cdea (patch)
tree9efcdf21dfed2199a78e39f20ff0f422bda3901b /src
parentbdf55f62a258cbd5e3844775a992415e22373387 (diff)
Cocoa: Fix crash when disconnecting an AirDisplay monitor.
There are some cases where unplugging a monitor temporarily leaves a QCocoaScreen object with an invalid m_screenIndex. Debugging shows that the OS does not report the screen update before Qt attempts a repaint. This calls devicePixelRatio(), which calls osScreen(), and the index for the screen is out of bounds. By temporarily exiting updateGeometry() when the screen is unavailable, we avoid the crash. The OS quickly reports the monitor state change and everything returns to normal, unnoticed to application. Task-number: QTBUG-37606 Change-Id: Iacb2ff22bd3df72a5d87b2289242fb393625af57 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index 412818ae47..9d5388d33b 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -81,12 +81,16 @@ QCocoaScreen::~QCocoaScreen()
NSScreen *QCocoaScreen::osScreen() const
{
- return [[NSScreen screens] objectAtIndex:m_screenIndex];
+ NSArray *screens = [NSScreen screens];
+ return ((NSUInteger)m_screenIndex < [screens count]) ? [screens objectAtIndex:m_screenIndex] : nil;
}
void QCocoaScreen::updateGeometry()
{
NSScreen *nsScreen = osScreen();
+ if (!nsScreen)
+ return;
+
NSRect frameRect = [nsScreen frame];
if (m_screenIndex == 0) {
@@ -143,7 +147,8 @@ qreal QCocoaScreen::devicePixelRatio() const
{
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7) {
- return qreal([osScreen() backingScaleFactor]);
+ NSScreen * screen = osScreen();
+ return qreal(screen ? [screen backingScaleFactor] : 1.0);
} else
#endif
{