Merge pull request #1485 from mingulov/menu_cast

CCMenu - prevent a crash if some child item is not CCMenuItem
This commit is contained in:
minggo 2012-10-21 19:18:20 -07:00
commit 677ba22b5c
1 changed files with 4 additions and 4 deletions

View File

@ -652,16 +652,16 @@ CCMenuItem* CCMenu::itemForTouch(CCTouch *touch)
CCObject* pObject = NULL;
CCARRAY_FOREACH(m_pChildren, pObject)
{
CCNode* pChild = dynamic_cast<CCNode*>(pObject);
if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled())
CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
if (pChild && pChild->isVisible() && pChild->isEnabled())
{
CCPoint local = pChild->convertToNodeSpace(touchLocation);
CCRect r = ((CCMenuItem*)pChild)->rect();
CCRect r = pChild->rect();
r.origin = CCPointZero;
if (r.containsPoint(local))
{
return (CCMenuItem*)pChild;
return pChild;
}
}
}