Skip to content

Commit

Permalink
From Ulrich Hertlein, Added some error checks and memory cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertosfield authored and casallas committed Sep 30, 2014
1 parent 290eb65 commit 26c313d
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/osgViewer/DarwinUtils.mm
Expand Up @@ -56,15 +56,40 @@ size_t displayBitsPerPixel( CGDirectDisplayID displayId )
return CGDisplayBitsPerPixel(displayId);
#else
CGDisplayModeRef mode = CGDisplayCopyDisplayMode(displayId);
size_t depth = 0;
if (!mode)
{
OSG_WARN << "CGDisplayCopyDisplayMode returned NULL" << std::endl;
return 0;
}

CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(mode);
if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
if (!pixEnc)
{
OSG_WARN << "CGDisplayModeCopyPixelEncoding returned NULL" << std::endl;
CGDisplayModeRelease(mode);
return 0;
}

size_t depth = 0;
if (CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
{
depth = 32;
else if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
}
else if (CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
{
depth = 16;
else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
}
else if (CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
{
depth = 8;
}
else
{
OSG_WARN << "Unable to match pixel encoding '" << CFStringGetCStringPtr(pixEnc, kCFStringEncodingUTF8) << "'" << std::endl;
}

CGDisplayModeRelease(mode);
CFRelease(pixEnc);

return depth;
#endif
Expand Down

0 comments on commit 26c313d

Please sign in to comment.