when click ControlButton and remove itself is is crash.it is a bug?

testbtn = CommonTools::addButton(“cancel.png”, this, cccontrol_selector(GameUILayer::clickClose));
testbtn->setSwallowsTouches(true);
this->addChild(testbtn);
testbtn->setPosition( ccp(300,300) );
}

void GameUILayer::clickClose(Object *sender, Control::EventType controlEvent)
{
this->removeChild(testbtn);
}
// 就是说 创建一个按钮 点击他 然后移除自己 就会报错 请问如何避免这个问题呢?

From the codes you pasted. I can not find the error.
May be you should paste the logic of CommonTools::addButton().
Did you use the button in other place?

@zhangxm
hi , the code is

ControlButton* CommonTools::addButton(const char* spriteFrameName, Object* target, Control::Handler action)
{
	ControlButton *btn1 = ControlButton::create();
	setBtn(btn1, spriteFrameName, target, action);
	return btn1;
}

ControlButton* CommonTools::addButton(string title, const char * fontName, float fontSize, const char* spriteFrameName, Object* target, Control::Handler action)
{
	ControlButton *btn1 = ControlButton::create(title, fontName, fontSize);
	setBtn(btn1, spriteFrameName, target, action);
	return btn1;
}

void CommonTools::setBtn(ControlButton* btn1, const char* spriteFrameName, Object* target, Control::Handler action)
{
	//btn1->setTouchPriority(Btn_Priority);
	
	btn1->setTouchMode(Touch::DispatchMode::ONE_BY_ONE);

	SpriteFrame *sp = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName);
	
	btn1->setBackgroundSpriteFrameForState( sp, Control::State::NORMAL );
	btn1->setBackgroundSpriteFrameForState( sp, Control::State::HIGH_LIGHTED );
	
	btn1->setPreferredSize( sp->getOriginalSizeInPixels() );
	
	btn1->addTargetWithActionForControlEvents( target, action, Control::EventType::TOUCH_UP_INSIDE );
}

and i use the sample , it is same crash。so u not crash?

in chinese is: 我拿官方的例子改 也出了同样的问题 。
我现在正在做一个panel 里面有一个按钮 点击按钮后关闭面板 然后移除所有显示对象。
在2.2的时候还没事呢

Sorry, can not find bug.
Could you please upload a simple demo to reproduce it?
What’s the engine version you use?

@zhangxm the verison is 3.0 beta2
i can remove it in the next time.