Re: Crashing View
Re: Crashing View
- Subject: Re: Crashing View
- From: Nick Zitzmann <email@hidden>
- Date: Sat, 7 Apr 2007 16:18:42 -0600
On Apr 7, 2007, at 4:00 PM, Tom Marchand wrote:
I've got a custom view that has a transparent background created
with colorWithDeviceRed. Everything works ok until I resize the
window, which results in the app crashing. Any help would be
appreciated. Here's the code:
You did not ask a question in your post (that would be helpful next
time), so I am assuming your question is "why is this crashing?" If
so, then here is your answer:
- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil)
{
BackGround=[NSColor colorWithDeviceRed:.50 green:0.50 blue:.50
alpha:.50];
You're creating a temporary object here. It will be deallocated when
the autorelease pool is popped. Since resizing the window is
triggering a redraw, the draw method is trying to access a
deallocated object, which is causing the crash.
If your intention is to keep "BackGround" around, you need to retain
it first. I would recommend reading up on Cocoa memory management.
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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