Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Simulacrotron opened this issue Nov 18, 2011 · 7 comments
Open

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

Simulacrotron opened this issue Nov 18, 2011 · 7 comments

Comments

@Simulacrotron
Copy link

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
Copy link

dimme commented Dec 10, 2011

I can confirm this issue.

@domesticcatsoftware
Copy link
Owner

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

@dimme
Copy link

dimme commented Jun 2, 2012

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

@tipycalFlow
Copy link

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

@brspurri
Copy link

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

@ilbanshee
Copy link

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
Copy link

The above solution worked great!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants