krzysztofzablocki/CCNode-SFGestureRecognizers — pull request #6 by KingOfTheHuns (2013-06-18 20:03:58+00:00)
Title: Fix: crashes because delegate not cleaned up properly

Hi,

First, I'd like to thank you for creating this great pod for cocos2d. It is really great. :)

While I was testing it in my prototype app I stumbled upon occasional crashes during scene transition. (BTW: I've used CCNode-SFGestureRecognizers along with other pods like cocos2d and without ARC.)
I've investigated the problem and found that removeGestureRecognizer: did not clean up properly aGestureRecognizer.delegate. In addition there was an incorrect call "objc_setAssociatedObject(self, AH_BRIDGE(UIGestureRecognizerSFGestureRecognizersPassingDelegateKey), nil, OBJC_ASSOCIATION_RETAIN);" Here the problem was that the method should use aGestureRecognizer instead of self. Probably it was a typo.

Anyway, not setting aGestureRecognizer.delegate to nil caused that originalDelegate member of __SFGestureRecognizersPassingDelegate was not set to nil as well and in some cases after the removeGestureRecognizer called __SFGestureRecognizersPassingDelegate object still has received gestureRecognizerShouldBegin callback. The gestureRecognizerShouldBegin callback was referring to originalDelegate and it caused a crash.

The changes I propose fix this problem. (Maybe in ARC case this problem wouldn't surface since is a weak pointer so it will be reset to nil upon it is released.)