• 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: EXC_BAD_ACCESS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EXC_BAD_ACCESS


  • Subject: Re: EXC_BAD_ACCESS
  • From: Roland King <email@hidden>
  • Date: Thu, 11 Mar 2010 21:54:39 +0800

isn't this almost exactly the same question you asked a week ago? It looks like you did 1/2 of what Graham told you then but didn't totally understand his answer.

Same answer, you're setting path to a newly-created NSBezierPath you don't own and overwriting the one you alloc/init'ed earlier. So you're leaking the first one and the second one you don't own so it's being released causing the bad access error.

this line by the way

	path = [ path init ];

is illegal, you can't init something twice. The second version happens to work (even apart from the illegal extra init) because it appends a path to the bezier which already exists, which you then aren't leaking.

It might help to go read the creation/destruction of objects and memory management chapters again until it clicks.


On 11-Mar-2010, at 9:38 PM, Billy Flatman wrote:

> Hi All,
>
> I'm getting a 'EXC_BAD_ACCESS' error when calling the fill on a NSBezierPath.
> Below is an outline of my code.
>
>
> @interface Shape : NSObject {
> 	NSBezierPath *path;
> }
> - (void)paint;
> @end
>
> @implementation Shape
> - (void) paint {
> 	[[NSColor redColor] set];
> 	[path fill];
> }
> @end
>
> @interface Square : Shape <Moveable> {}
> - (Square *) initSquare;
> - (void)initBezierPath;
> @end
>
> @implementation Square
> - (Square *) initSquare {
> 	self = [super init];
> 	if (self) {
> 		path = [[NSBezierPath alloc] init];
> 		[self initBezierPath];
> 	}
> 	return self;
> }
> - (void) initBezierPath {
> 	path = [NSBezierPath bezierPathWithRoundedRect:NSMakeRect(0,0,10,10)
> 				       xRadius:5
> 				       yRadius:5];
> 	[path closePath];
> }
> @end
>
> it works if I change initBezierPath content to:
>
> path = [path init];
> [path appendBezierPathWithRoundedRect:r
> 			      xRadius:5
>    			      yRadius:5];
> [path closePath];
>
> From the main body I initialise a Square and call it's paint method in the drawRect method of an NSView.
>
> Any help would be greatly appreciated.
>
> Billy Flatman
> 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

_______________________________________________

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: 
 >EXC_BAD_ACCESS (From: Billy Flatman <email@hidden>)

  • Prev by Date: Re: EXC_BAD_ACCESS
  • Next by Date: Re: Help visualizing something in IB
  • Previous by thread: Re: EXC_BAD_ACCESS
  • Next by thread: View does not get refreshed after Window deminimized...
  • Index(es):
    • Date
    • Thread