Search code examples
iphoneiosxcodeexc-bad-accesstouchesbegan

EXC_BAD_ACCESS right after touchesBegan


I have started a very simple project to learn iOS programming, but I get EXC_BAD_ACCESS after touchesBegan.

You can download the project from DropBox here .

I basically have a UIView subclass that should draw circles wherever the user is touching.

Very simple but I cannot make it work.

Any help is highly appreciated. Thanks!

EDIT Turns out the problem is this line of code in touchesBegan:

    ts = [NSMutableSet setWithSet: [event touchesForView:self]];

That I changed into:

    ts = [[NSMutableSet setWithSet: [event touchesForView:self]] retain];

Solution

  • Why don't you use ARC??? :) Its good! You do not retain your ts set. Note, that setWithSet: returns you autoreleased instance. (The red circle looks promising :))