RTTI doesn't work properly on Android (can't dynamic_cast to CCRGBAProtocal)

It seems that there is difference how dynamic_cast works on iOS and Android.

Here is a quick test:

    CCNode* rgba = CCNode::node();
    rgba->setPosition( ccp(200, 200) );
    rgba->addChild( CCSprite::spriteWithSpriteFrameName( "Papa_fall_1" ) );
    this->addChild(rgba);

    if (dynamic_cast(rgba->getChildren()->objectAtIndex(0))) {
        CCLOG("It is CCNode");
    } else {
        CCLOG("NO");
    }

    if (dynamic_cast(rgba->getChildren()->objectAtIndex(0))) {
        CCLOG("It is CCRGBAProtocol");
    } else {
        CCLOG("NO");
    }

Obviously, CCSprite is CCGRBAProtocol so in the end log should have “It is CCNode” and “It is CCRGBAProtocol”.

On iOS it works as expected, however, on Android it displays only “It is CCNode” and then “NO” which means that it does not cast to CCRGBAProtocol.

Application.mk file already has APP_CPPFLAGS += -frtti

Any ideas why is it so?

I think it’s ndk’s rtti implementation bug.
Try using different STL libraty (gnustl_static / stlport_static / …)

Hi, this issue does exist on android platform. It’s because dynamic_cast is invoked in different shared library. Maybe we will make all modules packed into one shared library to resolve this odd bug.:frowning:

I’ve just compiled my game and cocos2d as a single shared library and the problem has gone.

How to set a single shared library to compiled?

You can try the latest code in github.
We build cocos2dx as a static lib.

:smiley: I was also suffering from this issue. compiling as statics solve the problem, thank goodness!

How too fix it… i don’t understand…

just change new cocos2dx core source?
or other action need??

How too fix it… i don’t understand…

just change new cocos2dx core source?
or other action need??

As Angus Comrie said.
Compile all native codes in one .so.

how too make…;;
1 *.so file.;;

now : change
—————————————————
cocos2d.so
cocosdenshion.so
game.so => cocos2d.so

like this??
In one file and copy all the file names do I need?

I Just type cast… like this…
it’s not a 100 % solution… but… it’s work…

  • before
    dynamic_cast<CCNode*>(rgba~~>getChildren~~>objectAtIndex~~>setOpacity;
    ~~ after
    CCSprite* pSprite = rgba~~>getChildren~~>objectAtIndex;
    pSprite~~>setOpacity;
    i am using only MenuItemImage…
    so… that code is working…~~_-;; and easy…