Re: First responder crashes in drawRect after processing keyDown
Re: First responder crashes in drawRect after processing keyDown
- Subject: Re: First responder crashes in drawRect after processing keyDown
- From: Ricky Sharp <email@hidden>
- Date: Tue, 5 Jun 2007 21:15:36 -0500
On Jun 5, 2007, at 9:02 PM, Tron Thomas wrote:
I have written a Cocoa application which crashes under certain
conditions, and I don't understand why.
I created an Objective-C++ class name MyView which subclasses
NSView. I created an instance of the view in the main window for
the NIB resource file, and made that view the delegate for the window.
Here in essence, is the source code for the class:
#import <Cocoa/Cocoa.h>
@interface MyView : NSView
{
@private
NSDictionary* _attributes;
}
@end
#import "MyView.h"
@implementation MyView
- (void)awakeFromNib
{
NSFont* font = [NSFont userFontOfSize:64.0f];
_attributes =
[NSDictionary dictionaryWithObject:font
forKey:NSFontAttributeName];
}
[some code snipped]
- (void)drawRect:(NSRect)rect
{
NSSize size = [self bounds].size;
NSPoint point = { size.width * 0.5f, size.height * 0.5f };
NSString* text = @"A";
[text drawAtPoint:point withAttributes:_attributes];
}
@end
_attributes is being assigned an auto-released value (see
dictionaryWithObject:forKey). You'll need to retain it.
Definitely read up on memory management. Links are sent out on
occasion in the moderator's e-mail with subject "List guidelines and
related resources"
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.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