OSDN Git Service

Protected against CGBitmapContextCreate() failing while loading a tile set.
authorEric Branlund <ebranlund@fastmail.com>
Fri, 21 Feb 2020 02:40:07 +0000 (18:40 -0800)
committerEric Branlund <ebranlund@fastmail.com>
Fri, 21 Feb 2020 02:40:07 +0000 (18:40 -0800)
src/main-cocoa.m

index d467ecf..1ef7623 100644 (file)
@@ -2185,14 +2185,16 @@ static CGImageRef create_angband_image(NSString *path)
 
         /* Draw the source image flipped, since the view is flipped */
         CGContextRef ctx = CGBitmapContextCreate(NULL, width, height, CGImageGetBitsPerComponent(decodedImage), CGImageGetBytesPerRow(decodedImage), CGImageGetColorSpace(decodedImage), contextBitmapInfo);
-        CGContextSetBlendMode(ctx, kCGBlendModeCopy);
-        CGContextTranslateCTM(ctx, 0.0, height);
-        CGContextScaleCTM(ctx, 1.0, -1.0);
-        CGContextDrawImage(ctx, CGRectMake(0, 0, width, height), decodedImage);
-        result = CGBitmapContextCreateImage(ctx);
-
-        /* Done with these things */
-        CFRelease(ctx);
+       if (ctx) {
+           CGContextSetBlendMode(ctx, kCGBlendModeCopy);
+           CGContextTranslateCTM(ctx, 0.0, height);
+           CGContextScaleCTM(ctx, 1.0, -1.0);
+           CGContextDrawImage(
+               ctx, CGRectMake(0, 0, width, height), decodedImage);
+           result = CGBitmapContextCreateImage(ctx);
+           CFRelease(ctx);
+       }
+
         CGImageRelease(decodedImage);
     }
     return result;