Re: NSBezierPath EXC_BAD_ACCESS issues.
Re: NSBezierPath EXC_BAD_ACCESS issues.
- Subject: Re: NSBezierPath EXC_BAD_ACCESS issues.
- From: Billy Flatman <email@hidden>
- Date: Wed, 3 Mar 2010 13:14:41 +0000
Hi Graham,
Thanks for your help, I've implemented your suggestions and it's working great, I just have one quick question if you don't mind.
I'm new to Objective-C as you've probably gathered and am not 100% about how the memory management works. Will I be causing a memory leek with the line:
path = [[NSBezierPath alloc] bezierPath];
within my initialiseBezierPath method?
Thanks for your help,
Billy.
On 3 Mar 2010, at 12:48, Graham Cox wrote:
> Your setBezierPath method is making a new, autoreleased path, it isn't using the one you created at initialisation. That is then autoreleased leaving <path> stale, hence the crash. You're also leaking the first path you made.
>
> If setBezierPath is there to simply set up the bezier path, it shouldn't make another path, you already made it, but also it shouldn't be named set...<Something> as it's not setting anything. Call it initialiseBezierPath for example.
>
>
> --Graham
>
>
>
> On 03/03/2010, at 11:34 PM, Billy Flatman wrote:
>
>> Hi all,
>>
>> I have a shape class containing an
>>
>> attribute:
>> NSBezierPath *path;
>>
>> initialisation:
>> path = [[NSBezierPath alloc] init];
>> [self setBezierPath];
>>
>> setBezierPath:
>> path = [NSBezierPath bezierPath];
>> then add the paths and close path.
>>
>> paint:
>> [path setLineWidth: 1];
>> [path fill];
>>
>> It all worked well when I had the setBezierPath method called from paint, but since only calling setBezierPath in an update method and during initialisation, I've started getting a exc_bad_access exception when path is called in the paint method.
>>
>> 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