layer's destructor has not be called when using the init method of the MenuItem's child class.
layer's destructor has not be called when using the init method of the MenuItem's child class.
Bug #5944 [New]
@twolight
This issue has been solved here: https://github.com/cocos2d/cocos2d-x/pull/8032
Status: | New | |
---|---|---|
Start date: | 2014-09-17 | |
Priority: | Low | |
Due date: | 2014-09-19 | |
Assignee: | - | |
% Done: | 0% |
|
Category: | - | |
Target version: | - |
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);
}