Forums » C++ Framework » [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite »
| Diego R | [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|---|---|---|---|
|
Added by Diego R over 1 year ago
After the latest Cocos changes where dynamic cast were introduced, I am having the following issue: I declared: class TouchSprite : public CCSprite, public CCTargetedTouchDelegate and in the onEnter function I am doing: void TouchSprite::onEnter()
{ After tracing, I found that bool CCTouchHandler::initWithDelegate(CCTouchDelegate *pDelegate, int nPriority) fails in (dynamic_cast<CCObject*>(pDelegate))->retain(); because the dynamic cast fails and returns NULL. The code works fine when compiled using Xcode in iOS, but fails in Android. Any ideas?
Thanks! |
||
| Minggo Zhang | RE: [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|
Added by Minggo Zhang over 1 year ago
Yes, it crashed in (dynamic_cast<CCObject*>(pDelegate))->retain(). Thank you. |
||
| Minggo Zhang | RE: [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|
Added by Minggo Zhang over 1 year ago
I do the following test: 1. add dynamic_cast<CCObject*>(this)->retain()before CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true) It also crashed at CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true). 2. change class Paddle : public CCSprite, public CCTargetedTouchDelegateto class Paddle : public CCTargetedTouchDelegate, public CCSprite It also crashed. CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true) is called in other tests, but they are ok. I don't know why. |
||
| Diego R | RE: [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|
Added by Diego R over 1 year ago
Hi Minggo, Thanks for taking a look. The problem is that the way the paddle demo works is the cleanest way to track sprites touches. Do we have any C++ wizards in the forums who can help? Thanks! |
||
| Minggo Zhang | RE: [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|
Added by Minggo Zhang over 1 year ago
In MenuTest.h, MenuLayer1 also invoke CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true), it works ok. class MenuLayer1 : public CCLayer to class MenuLayer1 : public CCLayer, public CCTextureProtocol to make it inherits from multiple classes, it also works ok. Both CCLayer and CCSprite inherit from multiple classes, and both of them inherit from CCNode. But I don't know why. |
||
| Andre Rudlaff | RE: [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|
Added by Andre Rudlaff over 1 year ago
The problem is still there with CCKeypadDelegate. I'm not sure on the perfect solution though. I guess the reason why the layer approach works is, that CCKeypadDelegate (and CCTouchDelegate) are extended by CCLayer directly (i.e. library code). So I guess there may be three solutions to this problem: |
||
| Minggo Zhang | RE: [UPDATE] Touches TEST in Android crashes - Dynamic cast fails when inheriting from CCSprite | ||
|
Added by Minggo Zhang over 1 year ago
We can not remove rtti, because we have to use multiple inherit. |
(1-6/6)