Ticket #18015: CGDisplayModeCopyPixelEncoding_WX_3_0_BRANCH.diff

File CGDisplayModeCopyPixelEncoding_WX_3_0_BRANCH.diff, 1.9 KB (added by botg, 3 years ago)

Patch for WX_3_0_BRANCH

  • src/osx/utils_osx.cpp

    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() 
    7777        CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
    7878        CFStringRef encoding = CGDisplayModeCopyPixelEncoding(currentMode);
    7979       
    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
    9092        CGDisplayModeRelease(currentMode);
    9193    }
    9294    else