ECX_BAD_ACCESS when enabling touch

Hello,

I get a ECX_BAD_ACCESS when i enable touch using:

this->setTouchEnabled(true);

The bad access happens in:

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

++m_uReference;
}

called from CCTouchHandler::initWithDelegate.

Am I doing something wrong?

I am using 2.0.1.

Thanks!

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