Fix crash when switching between monitors in wxOSX
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. Closes #18015.
This commit is contained in:
parent
be37dd4862
commit
26f48c225e
@ -66,21 +66,22 @@ bool wxColourDisplay()
|
|||||||
// Returns depth of screen
|
// Returns depth of screen
|
||||||
int wxDisplayDepth()
|
int wxDisplayDepth()
|
||||||
{
|
{
|
||||||
int theDepth = 0;
|
|
||||||
|
|
||||||
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
|
CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
|
||||||
CFStringRef encoding = CGDisplayModeCopyPixelEncoding(currentMode);
|
CFStringRef encoding = CGDisplayModeCopyPixelEncoding(currentMode);
|
||||||
|
|
||||||
if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
|
||||||
theDepth = 32;
|
|
||||||
else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
|
||||||
theDepth = 16;
|
|
||||||
else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
|
||||||
theDepth = 8;
|
|
||||||
else
|
|
||||||
theDepth = 32; // some reasonable default
|
|
||||||
|
|
||||||
CFRelease(encoding);
|
int theDepth = 32; // some reasonable default
|
||||||
|
if(encoding)
|
||||||
|
{
|
||||||
|
if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
||||||
|
theDepth = 32;
|
||||||
|
else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
||||||
|
theDepth = 16;
|
||||||
|
else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
||||||
|
theDepth = 8;
|
||||||
|
|
||||||
|
CFRelease(encoding);
|
||||||
|
}
|
||||||
|
|
||||||
CGDisplayModeRelease(currentMode);
|
CGDisplayModeRelease(currentMode);
|
||||||
|
|
||||||
return theDepth;
|
return theDepth;
|
||||||
|
Loading…
Reference in New Issue
Block a user