2014-02-27 103 views
0

我有iPhone 4S iOS 7.0.4 Jailbreak用户的TestFlight崩溃日志。在这条线上添加CGColorRef时CFArrayAppendValue崩溃

enter image description here

崩溃:

CFArrayAppendValue(colorArray, lighterColor); 

在崩溃发生全法:

- (UIImage *) imageWithColor:(UIColor *)color_ Height:(CGFloat)height_ Retina:(BOOL)retina_ 
{ 
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(1.0f, height_), YES, retina_ ? 2.0f : 1.0f); 
    CFMutableArrayRef colorArray = CFArrayCreateMutable(NULL, 2, &kCFTypeArrayCallBacks); 
    CGColorRef lighterColor = CGColorRetain([[color_ lighterColor] CGColor]); 
    CGColorRef darkerColor = CGColorRetain([[color_ darkerColor] CGColor]); 
    CFArrayAppendValue(colorArray, lighterColor); 
    CFArrayAppendValue(colorArray, darkerColor); 
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB(); 
    CGGradientRef gradient = CGGradientCreateWithColors(space, colorArray, NULL); 
    CGContextDrawLinearGradient(UIGraphicsGetCurrentContext(), gradient, CGPointMake(0.0f, 0.0f), CGPointMake(1.0f, height_), kCGGradientDrawsBeforeStartLocation); 
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    CGColorRelease(lighterColor); 
    CGColorRelease(darkerColor); 
    return image; 
} 

我很想知道如何处理这个问题。

任何帮助表示赞赏!

+0

验证'lighterColor'不是NULL,然后再将它添加到数组中。 – Emmanuel

回答

0

您崩溃的原因是传递给CFArrayAppendValue的值是NULL。或者说,这是保留回调所不希望的。有效的CGColorRef将与保留回调一起正常工作。

看着上面粘贴的代码,可能的原因是color_为零。这会导致lighterColor为零,并且其CGColor成员为NULL

在此方法中添加一个零检查或在早期调试您的应用程序。

+0

我添加了一行来检查color_是否为零。如果它是零,我使用[UIColor whiteColor]。仍然崩溃! – iWheelBuy

+0

在同一个地方?这是不太可能的。你可以验证lighterColor不是NULL吗? – Buzzy

+0

我将在下次更新中实施此验证 – iWheelBuy