ECX_BAD_ACCESS when enabling touch

ECX_BAD_ACCESS when enabling touch
0.0 0



I get a ECX_BAD_ACCESS when i enable touch using:


The bad access happens in:

void CCObject::retain(void)
CCAssert(m_uReference > 0, “reference count should greater than 0”);


called from CCTouchHandler::initWithDelegate.

Am I doing something wrong?

I am using 2.0.1.



Is it break at CCAssert?


Usually when a BAD ACCESS error happens, you are accessing an object that is NULL.


It is breaking on assert but its not asserting. Since it is BAD_ACCESS I guess that the object does not exist.

I guess the CCLayer object (my scene) that is trying to be registered as touch delegate does not exist, but why?


Did you super your CCLayer object before using setTouchEnabled( ) ? Your init( ) method should have something like this at the first line:

if ( !CCLayer::init( ) ) return false;


Yes, I have…

This is driving me nuts!

Could it be a bug in 2.0.1?


Doh, I found the problem. In my layer subclass:

class GameScene : public cocos2d::CCLayer {

I forgot the public keyword.

Thanks for the help