Loic Argelies [Potential Bug] CCFadeOut causes a crash when applied to CCMenuItem and m_pSelectedImage is NULL
Posts 6
Added by Loic Argelies over 1 year ago

I created CCMenuItem elements with no 'selected' image (ie, set to NULL). When trying to run a CCFaceOut action on the CCMenuItem, the application crashes on null pointer access on this line:

void CCMenuItemSprite::setOpacity(GLubyte opacity)
    {
        m_pNormalImage->convertToRGBAProtocol()->setOpacity(opacity)
        m_pSelectedImage->convertToRGBAProtocol()->setOpacity(opacity); // CRASH HERE as m_pSelectedImage is NULL

        if (m_pDisabledImage)
        {
            m_pDisabledImage->convertToRGBAProtocol()->setOpacity(opacity);
        }
    }

To fix, I replaced by the following:

void CCMenuItemSprite::setOpacity(GLubyte opacity)
    {
        m_pNormalImage->convertToRGBAProtocol()->setOpacity(opacity);

        if (m_pSelectedImage)  // <--- ADDED THIS LINE
            m_pSelectedImage->convertToRGBAProtocol()->setOpacity(opacity);

        if (m_pDisabledImage)
        {
            m_pDisabledImage->convertToRGBAProtocol()->setOpacity(opacity);
        }
    }

Keep up the good work.

Best,

RongHong Huang RE: [Potential Bug] CCFadeOut causes a crash when applied to CCMenuItem and m_pSelectedImage is NULL
Posts 171
Added by RongHong Huang over 1 year ago

yep, this is a bug, thank you and it will be corrected by Bug #715(http://www.cocos2d-x.org/issues/715)


(1-1/1)