New issue
 Projects > cocos2d-x > Issues > Bug #5944

layer's destructor has not be called when using the init method of the MenuItem's child class.

Bug #5944 [New]
503009358@qq.com 2014-09-19 02:38 . Updated over 6 years ago

all the MenuItem child class like MenuItemSprite have the init method.

// XXX deprecated
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, Ref* target, SEL_MenuHandler selector)
{
target = target;
CC_SAFE_RETAIN(_target); // may be a bug.
return initWithNormalSprite(normalSprite, selectedSprite, disabledSprite, std::bind(selector,target, std::placeholders::_1) );
}
and the MenuItem's destructor
MenuItem::~MenuItem()
{
CC_SAFE_RELEASE(
target);
}
after adding a Menu,the layer's reference is counted.when the layer check the reference to be destroyed,~MenuItem() has not been called.so layer's destructor can not be called. I notice the init method is deprecated,but it's not easy to find for developer.

ps:
there is not bug in other init method.
bool MenuItemSprite::initWithNormalSprite(Node* normalSprite, Node* selectedSprite, Node* disabledSprite, const ccMenuCallback& callback)
{
MenuItem::initWithCallback(callback);
setNormalImage(normalSprite);
setSelectedImage(selectedSprite);
setDisabledImage(disabledSprite);

if(_normalImage)
{
    this->setContentSize(_normalImage->getContentSize());
}

setCascadeColorEnabled(true);
setCascadeOpacityEnabled(true);

return true;

}

owen 2014-09-19 02:53

@twolight

This issue has been solved here: https://github.com/cocos2d/cocos2d-x/pull/8032

Atom PDF

Status:New
Start date:2014-09-17
Priority:Low
Due date:2014-09-19
Assignee:-
% Done:

0%

Category:-
Target version:-