domesticcatsoftware / DCRoundSwitch

A 'modern' replica of UISwitch.
MIT License
765 stars 162 forks source link

When using ARC line 57 of DCRoundSwitchKnobLayer.m Crashes #10

Open Simulacrotron opened 12 years ago

Simulacrotron commented 12 years ago

Line 57 (CFArrayRef ColorsArray =...) crashes with ARC enabled. I'm not sure how to work around the issue. I know you have to make some modifications for C structs and ARC, but I don't know enough about C to make the changes. Anyone have a workaround?

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, CGColorRef startColor, CGColorRef endColor) { CGFloat colorStops[2] = {0.0, 1.0}; CGColorRef colors[] = {startColor, endColor}; CFArrayRef colorsArray = CFArrayCreate(NULL, (const void**)colors, sizeof(colors) / sizeof(CGColorRef), &kCFTypeArrayCallBacks); CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, colorsArray, colorStops); CFRelease(colorsArray); return gradient; }

dimme commented 12 years ago

I can confirm this issue.

domesticcatsoftware commented 12 years ago

Are you using a branch for this issue? I haven’t been able to reproduce this.

dimme commented 12 years ago

I don't remember, it was long time ago. However I solved it somehow.

tipycalFlow commented 12 years ago

I can confirm this issue as well. It happens on device only, though - works perfectly on simulator! Any solutions yet?

brspurri commented 11 years ago

I can confirm this as well. Not sure what's going on here.

ilbanshee commented 11 years ago

Also for me and only on device (runs perfectly on simulator), I've resolved changing

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, CGColorRef startColor, CGColorRef endColor)

signature in

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, UIColor* startColor, UIColor* endColor)

and implementing the function as follows:

CGGradientRef CreateGradientRefWithColors(CGColorSpaceRef colorSpace, UIColor* startColor, UIColor* endColor)
{
    CGFloat colorStops[2] = {0.0, 1.0};
    NSArray *colors =
    [NSArray arrayWithObjects:(__bridge id)startColor.CGColor, (__bridge id) endColor.CGColor, nil];
    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (__bridge CFArrayRef) colors, colorStops);

    return gradient;
}

(changing method's invocation accordingly)

not sure if is ok since I'm new to objective-c but seems to work at the moment...

andrew-soltan commented 11 years ago

The above solution worked great!!