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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:46:38+00:00 2026-05-20T15:46:38+00:00

I have the following problem. I’m writing my own class which must draw a

  • 0

I have the following problem. I’m writing my own class which must draw a circle of specified size, fill it with gradient.

I made it with a circle being a NSBezierPath, to which I draw my gradient using

[gradient drawInBezierPath:circle relativeCenterPosition:gradPoint]

So everything works great except one thing: when I execute the following command at the end of my drawRect: code:

[borderColor set]; 
[circle stroke];

I get the error: (Program recieved signal: “EXC_BAD_ACCESS”) and debugger points to the line with

[borderColor set];

I set borderColor as

[NSColor colorWithCalibratedRed:0.8 green:0.8 blue:0.8 alpha:1.0]

for example.

It only works normally if i set my borderColor as any predefined color: blackColor, clearColor, greenColor. But any one which I try to set manually, crashes.

Does somebody know about any restrictions about colors or something that could cause such problem? I didn’t find anything special about stroke color of BezierPath.

Thank you.

  • 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-20T15:46:38+00:00Added an answer on May 20, 2026 at 3:46 pm

    The problem is that you are not properly retaining the borderColor instance variable. The -colorWithCalibratedRed:green:blue:alpha: method creates an autoreleased object, which, unless you retain it, will be automatically autoreleased (and deallocated) once the application event loop returns. The next time around, when you try to send a message to the deallocated object, problems occur.

    The reason it happens to be working with -blackColor, -clearColor, etc. is pure luck (sort of). Those “convenience color” methods happen to return singleton instances that will never be deallocated. For example, if someone asks for -blackColor 1000 times, there’s no sense in wasting memory by creating 1,000 separate instances; instead, the single (shared) instance is returned. However, this is a private implementation detail that you generally should not rely on.

    How to correct this depends on how borderColor has been defined. If it’s defined and implemented as a property, and you’re setting it via the -setBorderColor: method, then make sure the property is defined as a retain:

    @property (retain) NSColor *borderColor;
    

    Or, if you’re setting the borderColor value by working with the instance variable directly, you should wrap it with a retain:

    // remember to safely release the old value if necessary 
    borderColor = [[NSColor colorWithCalibratedRed:0.8
                            green:0.8 blue:0.8 alpha:1.0] retain];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have following problem: I have a class Foo which encapsulates a web-api. the
if have the following problem: I have a List which i am going through
I have the following problem in Java: I have a base class and a
I have the following problem. I have to implement a class that has an
I have following problem: in my layout xml I have relative layout in which
Hey guy i have following problem: I have this line of code which includes
I have the following problem. I have a menu which is 1000px wide. The
I have following problem statement. Export a C++ class in the dll (un-managed). Create
I have following problem module core contains test utils which is resused in dependent
I have following problem: I have one activity in which I have two tabs

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.