• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSView colors
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSView colors


  • Subject: Re: NSView colors
  • From: Graham Cox <email@hidden>
  • Date: Sat, 26 Jul 2008 11:25:46 +1000

I suspect you are just assigning your ivar without retaining the colour. It gets autoreleased and so crashes when you access it later (stale reference).

blueColor probably continues to work because (as an internal optimisation) it just so happens that that is a singleton and isn't autoreleased, so even though you only have a weak reference to it, it remains valid.

A review of memory management in general should set you straight.

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/

cheers, Graham



On 26 Jul 2008, at 7:40 am, Ashley Perrien wrote:

I have a custom NSView that contains as an instance variable a color. If I set the color in init as lineColor = [NSColor blueColor]; all is well. If instead I use [NSColor colorWithCalibratedRed: 0.5 green: 0.5 blue: 1.0 alpha: 1.0], the program crashes if I try and access or change the color later. The initial draw using it is just fine. But the next time it's redrawn or if I change the color, everything crashes. I have the exact same problem in 2 completely different applications. I'd like to be able to initialize the colors with something other than the default redColor, blueColor, etc. I've also tried one or two of the other ways to specify values and have had the same problem. Any ideas on what's going on?

Ashley Perrien
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >NSView colors (From: Ashley Perrien <email@hidden>)

  • Prev by Date: Re: Drawing a drop-shadow around a view
  • Next by Date: Re: (Newb question?) Launching app on dock icon file drop?
  • Previous by thread: Re: NSView colors
  • Next by thread: Simple Modal Password Dialog
  • Index(es):
    • Date
    • Thread