JSTouchDelegate::ccTouchBegan error

I used targetTouchdelegate for my nodes, cc.registerTargettedDelegate(priority, swallowsTouches, node);
In simulator, it’s all ok. but when I run it in ipad, it always crashed here.
/////
bool JSTouchDelegate::ccTouchBegan(CCTouch pTouch, CCEventpEvent) {
CC_UNUSED_PARAM(pEvent);
jsval retval;
bool bRet = false;

js_proxy_t* p = jsb_get_js_proxy(_mObj);
CCAssert(p, “js object has been unrooted.”);

ScriptingCore::getInstance()->executeCustomTouchEvent(CCTOUCHBEGAN,
pTouch, _mObj, retval);
if(JSVAL_IS_BOOLEAN(retval)) {
bRet = JSVAL_TO_BOOLEAN(retval);
}

return bRet;
};

p is null ptr. who can tell me how to resolve it?
My version is 2.1.4

I met the same problom, anyone knows how to solve this? I use cocosbuilder and cocos2d-jsb

擦泪 哥也刚遇到这个问题,

I’ve solved my problem
because I use cocosbulder, so I have to use cc.cc.registerTargettedDelegate like this:cc.registerTargettedDelegate(cc.MENU_HANDLER_PRIORITY, true, this.rootNode);
previously, I lost .rootNode

Or maybe you should use
this.rootNode.setTouchPriority(priority);
this.rootNode.setTouchMode(cc.TOUCHES_ONE_BY_ONE);

instead of
cc.registerTargettedDelegate(priority, swallowsTouches, node);

I noticed that if I use cc.registerTargettedDelegate in onDidLoadFromCCB, it will call addTargetedDelegate(this,priority,swallowsTouches); in cocos2d_specifics.cpp
But when this layer call onEnter in c++, it will call registerWithTouchDispatcher and finally will call addTargetedDelegate again.
So, addTargetedDelegate actually called twice with the same layer. If I use the 2 line code at start it works OK!


Chinese version:
英语写的太烂 中文写一遍
就是在onDidLoadFromCCB里调用 cc.registerTargettedDelegate 的话会调用addTargetedDelegate,然而在这个Layer调用onEnter的时候还是再调用到addTargetedDelegate一次。m_pHandlersToAdd->addObject(pHandler); m_pHandlersToAdd就添加了同一个pDelegate两次,这个界面关闭后,再点击屏幕我的程序就会产生和LZ一样的错误。
如果用:
this.rootNode.setTouchPriority(priority);
this.rootNode.setTouchMode(cc.TOUCHES_ONE_BY_ONE);
的话就只会在onEnter的时候调用到addTargetedDelegate。这样就OK啦~

Orca Chen wrote:

I used targetTouchdelegate for my nodes, cc.registerTargettedDelegate(priority, swallowsTouches, node);
In simulator, it’s all ok. but when I run it in ipad, it always crashed here.
/////
bool JSTouchDelegate::ccTouchBegan(CCTouch pTouch, CCEventpEvent) {
CC_UNUSED_PARAM(pEvent);
jsval retval;
bool bRet = false;
>
js_proxy_t* p = jsb_get_js_proxy(_mObj);
CCAssert(p, “js object has been unrooted.”);
>
ScriptingCore::getInstance()->executeCustomTouchEvent(CCTOUCHBEGAN,
pTouch, _mObj, retval);
if(JSVAL_IS_BOOLEAN(retval)) {
bRet = JSVAL_TO_BOOLEAN(retval);
}
>
return bRet;
};
>
p is null ptr. who can tell me how to resolve it?
My version is 2.1.4