Crashes in CCMenuItem* CCMenu::itemForTouch(CCTouch *touch)

Hello, everybody.

When I start up my first demo in android(Windows) by following Tutorials.
The program Crashes in the function CCMenu::itemForTouch.(My NDK is 7rd, and used cocos2d-1.0.1-x-0.11.0, run in android 2.2 emulator).

When I make a little change to CCMenu::itemForTouch, the crash problem disappeared.
Is it a bug of cocos OR g++ ?

Hope for reply. Thanks.

Code is pasted below.


CCMenuItem* CCMenu::itemForTouch(CCTouch *touch)
{
CCPoint touchLocation = touch~~>locationInView);
touchLocation = CCDirector::sharedDirector~~>convertToGL;
if > 0)
{
CCObject* pObject = NULL;
CCARRAY_FOREACH
{
//CCNode* pChild = dynamic_cast<CCNode*>;
↑↑↑↑ ★★★ if I change dynamic_cast to the code below. The crash clear. It seems dynamic_cast got a wrong address.
CCNode* pChild = ;
if && pChild)>getIsEnabled)<— ★★★ it crashes here.
{
CCPoint local = pChild
>convertToNodeSpace(touchLocation);
CCRect r = ((CCMenuItem*)pChild)>rect;
r.origin = CCPointZero;
if )
{
return pChild;
}
}
}
}
return NULL;
}
——————

Just made a test. Paste up the test result.(use g++ 4.4.0.)
I create a CCMenuItemImage named pTestItem, and then do some cast as belows.

>> CCObject pTestObj1 = pTestItem;
>> CCObject
pTestObj2 = dynamic_cast<CCObject*>(pTestItem);

>> CCNode pTestNode1 = pTestItem;
>> CCNode
pTestNode2 = dynamic_cast<CCNode*>(pTestItem);

>> CCNode pTestNode3 = pTestObj1;
>> CCNode
pTestNode4 = dynamic_cast<CCNode*>(pTestObj1);

The address of each parment is below.
It seems pTestNode4 is strangely, got a wrong address.

pTestItem(x002713b0).

pTestObj1(x002713b4).
pTestObj2(x002713b4).

pTestNode1(x002713b0).
pTestNode2(x002713b0).
pTestNode3(x002713b0).
pTestNode4(x002713b8)

It is a matter of g++, may be you can refer http://gcc.gnu.org/faq.html#dso.
So we build cocos2d-x as a static lib, and it can resolve the problem.

Thank you for reply, Minggo Zhang.

I will try the static-lib way.