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 374223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:23:05+00:00 2026-05-12T14:23:05+00:00

I am confused why my app is crashing with this error. I have implemented

  • 0

I am confused why my app is crashing with this error.

I have implemented the displayLayer method (for rendering CALayer).
The first time this method runs things work fine. But subsequent calls to this is when the error occurs.

The error seems to occur when the self.bgColor is being set to the context fill color.
INTERESTINGLY… if I create the bgColor right before that line, things work. But as it stands, the bgColor is being created upon initialization of this class (the container of the displayLayer method).

-(void)displayLayer:(CALayer *)caLayer
{
  UIGraphicsBeginImageContext(caLayer.frame.size);
  CGContextRef context = UIGraphicsGetCurrentContext();    
  CGContextSetFillColorWithColor(context, self.bgColor);
  CGContextFillRect(context, CGRectMake(0, 0, 320, 25)); 
  [self drawText:context];
  // get image buffer
  UIImage *imageBuffer = UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();
  // set layer contents to image buffer
  caLayer.contents = (id)[imageBuffer CGImage];
}
  • 1 1 Answer
  • 1 View
  • 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-12T14:23:06+00:00Added an answer on May 12, 2026 at 2:23 pm

    I haven’t done much iPhone programming yet, and never used a CGColor instance variable, so what I would do is this:

    @interface {
        ....
        UIColor *bgColor;
        ....
    }
    @property (nonatomic, retain) UIColor *bgColor;
    ...
    @end
    
    @implementation
    @synthesize bgColor;
    - (id)init {
        ...
        self.bgColor = [UIColor blackColor];
        ...
    }
    -(void)displayLayer:(CALayer *)caLayer {
        ...
        CGContextSetFillColorWithColor(context, self.bgColor.CGColor);
        ...
    }
    ...
    @end
    

    [UIColor blackColor] returns an autoreleased object, and you assigned it to your instance variable without retaining it.

    Using self.bgColor instead of just bgColor in init and having set up the property to retain its value will make sure that the color is retained and can be used in displayLayer later on.

    As I mentioned I don’t have any experience with using CGColors directly, that’s why I’m using a UIColor in the above code. Please adjust as needed.

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

Sidebar

Related Questions

I'm writing my first Rails app and I'm confused by a method call that
I have just started designing for my first iOS app and I am confused
I have implemented Authlogic to my app, but I am confused about the sense
I'm confused by this behavior: I have an out-of-the-box MVC3 app. I haven't really
Ok, I'm confused.. I have an app that if I launch and use runs
Little confused, the basic spring mvc app has this: app-config.xml <context:component-scan base-package=org.springframework.samples.mvc.basic /> and
although I'm about to finish my first app, I'm still confused about the very
I'm writing my first location based android app, but got confused about some of
I'm building my first Backbone.js app and I'm confused about how much responsibility I'm
Hi I'm building my first MVC 2 app and I'm really confused by all

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.