Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGColorRef causing crash

I've had a crash in my code, and I've tracked it all the way back to a line crashing when being passed 2 CGColorRefs. Here are the objects:

CGColorRef startColor = [[UIColor colorWithWhite:0.92 alpha:1.0]CGColor];
CGColorRef endColor = [[UIColor colorWithWhite:0.94 alpha:1.0]CGColor];

NSLog(@"start: %@ end: %@", startColor, endColor);

The NSLog returns a crash. What's wrong with them?

EDIT - where it's crashing:

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat locations[] = { 0.0, 1.0 };
NSArray *colors = [NSArray arrayWithObjects:(__bridge_transfer id)startColor, (__bridge_transfer id)endColor, nil];
like image 786
Andrew Avatar asked Mar 18 '12 22:03

Andrew


1 Answers

ARC. ARC. ARC. UIColor->CGCOlor is one of ARC's big gotchas...

See a deep dive here:

http://weblog.bignerdranch.com/?p=296

And I wrote up some general best practices for ARC (including your problem) here:

http://amattn.com/2011/12/07/arc_best_practices.html

like image 81
amattn Avatar answered Oct 14 '22 04:10

amattn