I am using [UIColor colorWithPatternImage:]
and was expecting it to retain the image passed in. When I nil the image that is passed in, it is deallocated and any attempt to draw with the color results in a crash. Is this expected behavior or a bug?
// MyCustomUIImage is a sub-class with it's own custom data provider
UIImage* encodedImage = [[MyCustomUIImage alloc] initWithContentsOfFile:fileName];
UIColor* color = [UIColor colorWithPatternImage:encodedImage];
// color is then assigned to a singleton so it is never deallocated
// ... later ...
CGContextSetLineCap(ctx, kCGLineCapRound);
CGContextSetLineJoin(ctx, kCGLineJoinRound);
CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
CGContextSetMiterLimit(ctx, 0.1f);
CGContextSetShouldAntialias(ctx, YES);
CGContextSetAllowsAntialiasing(ctx, YES);
CGContextAddPath(ctx, self.path);
CGContextSetLineWidth(ctx, width);
CGContextSetStrokeColorWithColor(ctx, color.CGColor);
CGContextSetFillColorWithColor(ctx, NULL);
if (self.glowAmount > 0.0f && self.glowColor.alpha > 0.0f)
{
CGContextSetShadowWithColor(ctx, CGSizeZero, self.glowAmount, self.glowColor.CGColor);
}
CGContextSetBlendMode(ctx, blendMode);
// *** CRASHES HERE ***
CGContextDrawPath(ctx, kCGPathStroke);
UIColor does retain the UIImage, but it will not retain the data provider. I was releasing the data provider and that was causing the crash.