Open ghost opened 9 years ago
ControlSwitch* ControlSwitch::create
(Label* label, Label* onLabel, Label* offLabel, Scale9Sprite* switchSprite, MenuItem* thumb, MenuItem* onThumb, MenuItem* offThumb)
{
ControlSwitch *pRet = new ControlSwitch();
pRet->initWithMaskSprite(switchSprite, thumb, onThumb, offThumb);
pRet->autorelease();
if (label)
{
pRet->addLabel(label);
label->release();
// Set the labels' text color based on the switch's state
if (pRet->isOn())
{
label->setColor(pRet->getOnTitleColor());
}
else
{
label->setColor(pRet->getOffTitleColor());
}
}
if (onLabel)
{
pRet->addLabel(onLabel);
onLabel->release();
onLabel->setVisible(pRet->isOn());
}
if (offLabel)
{
pRet->addLabel(offLabel);
offLabel->release();
offLabel->setVisible(!pRet->isOn());
}
return pRet;
}
CCControlSwitch's internal methods assign a nullptr to Label* onLabel, Label* offLabel, which will crash when trying to add to the ClippingNode on line 196