]> git.saurik.com Git - wxWidgets.git/commitdiff
handling nil images correctly, solves #12956
authorStefan Csomor <csomor@advancedconcepts.ch>
Sun, 20 Feb 2011 06:31:12 +0000 (06:31 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Sun, 20 Feb 2011 06:31:12 +0000 (06:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66979 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/carbon/utilscocoa.mm

index af37cccbe5564f799ec96c5aa5b1718465e2046c..5109a17953b346a69e0f0ea1208de8be6a22e5c7 100644 (file)
@@ -408,19 +408,23 @@ WX_NSImage  wxOSXGetNSImageFromCGImage( CGImageRef image )
 CGImageRef wxOSXCreateCGImageFromNSImage( WX_NSImage nsimage )
 {
     // based on http://www.mail-archive.com/cocoa-dev@lists.apple.com/msg18065.html
-    
-    NSSize imageSize = [nsimage size];
-    CGColorSpaceRef genericRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 
-    CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 0, genericRGB, kCGImageAlphaPremultipliedFirst); 
-    NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
-    [NSGraphicsContext saveGraphicsState];
-    [NSGraphicsContext setCurrentContext:nsGraphicsContext];
-    [[NSColor whiteColor] setFill];
-    NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
-    [nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
-    [NSGraphicsContext setCurrentContext:nsGraphicsContext];
-    CGImageRef image = CGBitmapContextCreateImage(context);
-    CFRelease(context);
+
+    CGImageRef image = NULL;
+    if (nsimage != nil)
+    {
+        NSSize imageSize = [nsimage size];
+        CGColorSpaceRef genericRGB = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); 
+        CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, 0, genericRGB, kCGImageAlphaPremultipliedFirst); 
+        NSGraphicsContext *nsGraphicsContext = [NSGraphicsContext graphicsContextWithGraphicsPort:context flipped:NO];
+        [NSGraphicsContext saveGraphicsState];
+        [NSGraphicsContext setCurrentContext:nsGraphicsContext];
+        [[NSColor whiteColor] setFill];
+        NSRectFill(NSMakeRect(0.0, 0.0, imageSize.width, imageSize.height));
+        [nsimage drawAtPoint:NSZeroPoint fromRect:NSZeroRect operation:NSCompositeCopy fraction:1.0];
+        [NSGraphicsContext setCurrentContext:nsGraphicsContext];
+        image = CGBitmapContextCreateImage(context);
+        CFRelease(context);
+    }
     return image;
  }