• 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: First responder crashes in drawRect after processing keyDown
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >First responder crashes in drawRect after processing keyDown (From: Tron Thomas <email@hidden>)

  • Prev by Date: Re: First responder crashes in drawRect after processing keyDown
  • Next by Date: Best way to play a MP3?
  • Previous by thread: Re: First responder crashes in drawRect after processing keyDown
  • Next by thread: Best way to play a MP3?
  • Index(es):
    • Date
    • Thread