소스 검색

DisplayManagerOSX: potential robustness improvements

Clear m_osxDisplayModes on reinit. This gets rid of stale state, and
also fixes a minor memory leak. (This is probably not all that critical,
because if everything else is sane, the entries that are going to be
accessed would have been overwritten anyway.)

Check and log CGGetActiveDisplayList() and CGDisplaySetDisplayMode()
return values.
Vincent Lang 9 년 전
부모
커밋
af0584fe10
1개의 변경된 파일24개의 추가작업 그리고 3개의 파일을 삭제
  1. 24 3
      src/display/osx/DisplayManagerOSX.cpp

+ 24 - 3
src/display/osx/DisplayManagerOSX.cpp

@@ -10,14 +10,30 @@
 #include "utils/osx/OSXUtils.h"
 #include "DisplayManagerOSX.h"
 
+#include "QsLog.h"
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 bool DisplayManagerOSX::initialize()
 {
   int totalModes = 0;
-  
-  CGGetActiveDisplayList(MAX_DISPLAYS, m_osxDisplays, &m_osxnumDisplays);
+
   displays.clear();
 
+  for (int i = 0; i < m_osxDisplayModes.size(); i++)
+  {
+    if (m_osxDisplayModes[i])
+      CFRelease(m_osxDisplayModes[i]);
+  }
+  m_osxDisplayModes.clear();
+
+  CGError err = CGGetActiveDisplayList(MAX_DISPLAYS, m_osxDisplays, &m_osxnumDisplays);
+  if (err)
+  {
+    m_osxnumDisplays = 0;
+    QLOG_ERROR() << "CGGetActiveDisplayList returned failure:" << err;
+    return false;
+  }
+
   for (int displayid = 0; displayid < m_osxnumDisplays; displayid++)
   {
     // add the display to the list
@@ -83,7 +99,12 @@ bool DisplayManagerOSX::setDisplayMode(int display, int mode)
   CGDisplayModeRef displayMode =
   (CGDisplayModeRef)CFArrayGetValueAtIndex(m_osxDisplayModes[display], mode);
 
-  CGDisplaySetDisplayMode(m_osxDisplays[display], displayMode, NULL);
+  CGError err = CGDisplaySetDisplayMode(m_osxDisplays[display], displayMode, NULL);
+  if (err)
+  {
+    QLOG_ERROR() << "CGDisplaySetDisplayMode() returned failure:" << err;
+    return false;
+  }
 
   // HACK : on OSX, switching display mode can leave dock in a state where mouse cursor
   // will not hide on top of hidden dock, so we reset it state to fix this