dmitry
February 4, 2012, 7:03am
#1
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?
splash5
February 4, 2012, 3:53pm
#2
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.
dmitry
February 5, 2012, 9:31pm
#4
I’ve just compiled my game and cocos2d as a single shared library and the problem has gone.
wpalhm
February 9, 2012, 4:04am
#5
How to set a single shared library to compiled?
zhangxm
February 10, 2012, 6:18am
#6
You can try the latest code in github.
We build cocos2dx as a static lib.
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??
zhangxm
August 16, 2012, 9:04am
#10
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…