mirror of https://github.com/axmolengine/axmol.git
Merge pull request #1485 from mingulov/menu_cast
CCMenu - prevent a crash if some child item is not CCMenuItem
This commit is contained in:
commit
677ba22b5c
|
@ -652,16 +652,16 @@ CCMenuItem* CCMenu::itemForTouch(CCTouch *touch)
|
||||||
CCObject* pObject = NULL;
|
CCObject* pObject = NULL;
|
||||||
CCARRAY_FOREACH(m_pChildren, pObject)
|
CCARRAY_FOREACH(m_pChildren, pObject)
|
||||||
{
|
{
|
||||||
CCNode* pChild = dynamic_cast<CCNode*>(pObject);
|
CCMenuItem* pChild = dynamic_cast<CCMenuItem*>(pObject);
|
||||||
if (pChild && pChild->isVisible() && ((CCMenuItem*)pChild)->isEnabled())
|
if (pChild && pChild->isVisible() && pChild->isEnabled())
|
||||||
{
|
{
|
||||||
CCPoint local = pChild->convertToNodeSpace(touchLocation);
|
CCPoint local = pChild->convertToNodeSpace(touchLocation);
|
||||||
CCRect r = ((CCMenuItem*)pChild)->rect();
|
CCRect r = pChild->rect();
|
||||||
r.origin = CCPointZero;
|
r.origin = CCPointZero;
|
||||||
|
|
||||||
if (r.containsPoint(local))
|
if (r.containsPoint(local))
|
||||||
{
|
{
|
||||||
return (CCMenuItem*)pChild;
|
return pChild;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue