From 459d616efb48ecb2c157fecfb88e92a876db893d Mon Sep 17 00:00:00 2001 From: geoffcoward Date: Wed, 11 May 2016 17:45:26 -0700 Subject: Prevent demo crash in _convertToJPEGData when image data cannot be converted (#1420) * Prevent demo crash in _convertToJPEGData when image data cannot be converted. --- .../iOS UI Test/MCTMsgViewController.mm | 35 ++++++++++++---------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'example') diff --git a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm index db8a1122..714ff2de 100755 --- a/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm +++ b/example/ios/iOS UI Test/iOS UI Test/MCTMsgViewController.mm @@ -254,22 +254,27 @@ typedef void (^DownloadCallback)(NSError * error); [info setObject:(id) [NSNumber numberWithFloat:(float) IMAGE_PREVIEW_WIDTH] forKey:(__bridge id) kCGImageSourceThumbnailMaxPixelSize]; thumbnail = CGImageSourceCreateThumbnailAtIndex(imageSource, 0, (__bridge CFDictionaryRef) info); - CGImageDestinationRef destination; - NSMutableData * destData = [NSMutableData data]; - - destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) destData, - (CFStringRef) @"public.jpeg", - 1, NULL); + if (thumbnail != nil) { + + CGImageDestinationRef destination; + NSMutableData * destData = [NSMutableData data]; + destination = CGImageDestinationCreateWithData((__bridge CFMutableDataRef) destData, + (CFStringRef) @"public.jpeg", + 1, NULL); + + CGImageDestinationAddImage(destination, thumbnail, NULL); + CGImageDestinationFinalize(destination); + + CFRelease(destination); + + CFRelease(thumbnail); + CFRelease(imageSource); + + return destData; + } else { + return nil; + } - CGImageDestinationAddImage(destination, thumbnail, NULL); - CGImageDestinationFinalize(destination); - - CFRelease(destination); - - CFRelease(thumbnail); - CFRelease(imageSource); - - return destData; } @end -- cgit v1.2.3