diff --git a/cocos/ui/UIWidget.cpp b/cocos/ui/UIWidget.cpp index e183d6e..016cba5 100644 --- a/cocos/ui/UIWidget.cpp +++ b/cocos/ui/UIWidget.cpp @@ -812,6 +812,9 @@ void Widget::onTouchMoved(Touch *touch, Event* /*unusedEvent*/) void Widget::onTouchEnded(Touch *touch, Event* /*unusedEvent*/) { + // if self be released in propagateTouchEvent, may crash at setHighlighted. + // use retain() to avoid such case. + this->retain(); _touchEndPosition = touch->getLocation(); /* @@ -833,6 +836,7 @@ void Widget::onTouchEnded(Touch *touch, Event* /*unusedEvent*/) { cancelUpEvent(); } + this->release(); } void Widget::onTouchCancelled(Touch* touch, Event* /*unusedEvent*/)