Ticket #18015: CGDisplayModeCopyPixelEncoding_master.diff

File CGDisplayModeCopyPixelEncoding_master.diff, 1.8 KB (added by botg, 3 years ago)

Patch for master

  • src/osx/utils_osx.cpp

    commit f48f43261ce20779f0d3cd03e6503432fb06f2c9
    Author: Tim Kosse <tim.kosse@filezilla-project.org>
    Date:   Mon Dec 4 13:15:44 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 47e07ba683..ce280f6a5a 100644
    a b int wxDisplayDepth() 
    7171    CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
    7272    CFStringRef encoding = CGDisplayModeCopyPixelEncoding(currentMode);
    7373   
    74     if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
    75         theDepth = 32;
    76     else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
    77         theDepth = 16;
    78     else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
    79         theDepth = 8;
    80     else
    81         theDepth = 32; // some reasonable default
     74    theDepth = 32; // some reasonable default
     75    if(encoding)
     76    {
     77        if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
     78            theDepth = 32;
     79        else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
     80            theDepth = 16;
     81        else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
     82            theDepth = 8;
     83
     84        CFRelease(encoding);
     85    }
    8286
    83     CFRelease(encoding);
    8487    CGDisplayModeRelease(currentMode);
    8588
    8689    return theDepth;