Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7576229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:52:14+00:00 2026-05-30T16:52:14+00:00

wondering if someone could help me, but at the same time hopefully I can

  • 0

wondering if someone could help me, but at the same time hopefully I can help someone else too…

I have this problem with a CG Gradient that runs in the simulator but crashes on a device. I have searched and read the “CG Gradient runs on simulator, but not on iPhone” thread and I think its a similar problem, i.e due to me using ARC and it releasing the CGFloat too early, but I can’t quite get my head around how to implement the suggested fixes in relation to my code. (Please see the code at the bottom)

So I would be grateful if someone could help me with that part??

Anyway, the crash is so bad that it seems to continue to run the app on device in a really odd state, I can delete the app on the device and try to run it again with the offending code commented out, but it still causes a crash. No matter what I did it would not allow the app to run on the device again. Turns out that after some hours of scratching my head, that I needed to reset the iPad device I was attempting to deploy to as it was still holding onto the provisioning profile despite being closed / deleted from the device.

Hopefully, that makes some sense and can help someone too.

Thanks

CGFloat colors [] = { 
    0, 0, 0, 0, 
    0, 0, 0, 0
};    

CGFloat colors2 [] = { 
    190.00/255.00, 211.00/255.00, 60.00/255.00, 1.0, 
    138.00/255.00, 153.00/255.00, 43.00/255.00, 1.0
};

CGFloat colors3 [] = { 
    159.00/255.00, 164.00/255.00, 39.00/255.00, 1.0,
    110.00/255.00, 120.00/255.00, 27.00/255.00, 1.0 

};


CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient;
if (which_state==@"1") {
    gradient = CGGradientCreateWithColorComponents(baseSpace, colors2, NULL, 2);
    NSLog(@"which state has changed");
} else if (which_state==@"2"){
    gradient = CGGradientCreateWithColorComponents(baseSpace, colors3, NULL, 2);
} else if (which_state==@"3"){
    gradient = CGGradientCreateWithColorComponents(baseSpace, colors3, NULL, 2);
} else if (which_state==@"0"){
    gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2);
}


CGColorSpaceRelease(baseSpace), baseSpace = NULL;


CGContextSaveGState(context);
CGContextMoveToPoint(context, (width/4*0)+5, 0);
CGContextAddLineToPoint(context, (width/4*0)+30, self.frame.size.height-3);
CGContextAddLineToPoint(context, (width/4*1)+30, self.frame.size.height-3);
CGContextAddLineToPoint(context, (width/4*1)+5, 0);
CGContextAddLineToPoint(context, (width/4*0)+5, 0);
CGContextClip(context);

CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));

CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
CGGradientRelease(gradient), gradient = NULL;

CGContextRestoreGState(context);
CGContextFillPath(context);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:52:15+00:00Added an answer on May 30, 2026 at 4:52 pm

    You haven’t said how the app is crashing, but this looks wrong:

    CGGradientRef gradient; 
    if (which_state==@"1")
    ... 
    

    You are comparing strings using ==, and you should be using if ([which_state isEqualToString:@"1"]). == Checks for pointer equality, not string equality. From the look of your code it might be better to use an enum, but that’s a side issue.

    If your code goes through that set of if statements without hitting anything (since == may not give you a match) then you have an uninitialized CGGradientRef, which you later on attempt to draw and release. This would cause a crash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if someone could help me with this. I have defined my
I was wondering if someone could help me understand this problem. I prepared a
I might be asking too much, but I was wondering if someone could help
I was wondering if someone could help me get pointers to solve this problem.
I have an SQL problem i was wondering if someone could help me out.
I'm wondering if someone could help guide the approach to this fairly common problem:
Wondering if someone could help me. I have next to no knowledge with Ajax,
Hi I was wondering if someone could help me out. Ive tried Global but
I was wondering if someone could help me to get this method converted to
Im wondering if someone could help me. I have hundreds of people uploading images

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.