commit b795d7139774f2c56f11bc9cd952eadfec71d97e
Author: Tim Kosse <tim.kosse@filezilla-project.org>
Date: Mon Dec 4 13:09:02 2017 +0100
It is possible for CGDisplayModeCopyPixelEncoding to return NULL, e.g. during a switch between the built-in screen and an external monitor on a Macbook. Check the return value to prevent a crash.
diff --git a/src/osx/utils_osx.cpp b/src/osx/utils_osx.cpp
index d356a5c953..50e713e5a5 100644
a
|
b
|
int wxDisplayDepth() |
77 | 77 | CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay); |
78 | 78 | CFStringRef encoding = CGDisplayModeCopyPixelEncoding(currentMode); |
79 | 79 | |
80 | | if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) |
81 | | theDepth = 32; |
82 | | else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) |
83 | | theDepth = 16; |
84 | | else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) |
85 | | theDepth = 8; |
86 | | else |
87 | | theDepth = 32; // some reasonable default |
88 | | |
89 | | CFRelease(encoding); |
| 80 | theDepth = 32; // some reasonable default |
| 81 | if(encoding) |
| 82 | { |
| 83 | if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) |
| 84 | theDepth = 32; |
| 85 | else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) |
| 86 | theDepth = 16; |
| 87 | else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) |
| 88 | theDepth = 8; |
| 89 | CFRelease(encoding); |
| 90 | } |
| 91 | |
90 | 92 | CGDisplayModeRelease(currentMode); |
91 | 93 | } |
92 | 94 | else |