Merge pull request #7649 from andyque/fixPotentialCarshWhenRemoveSelfInCallback

fix potential crash when user remove self in widgets callback
This commit is contained in:
minggo 2014-08-05 09:46:00 +08:00
commit 6d09b00e1d
5 changed files with 32 additions and 1 deletions

View File

@ -472,6 +472,7 @@ void ListView::addEventListener(const ccListViewCallback& callback)
void ListView::selectedItemEvent(TouchEventType event)
{
this->retain();
switch (event)
{
case TouchEventType::BEGAN:
@ -497,7 +498,7 @@ void ListView::selectedItemEvent(TouchEventType event)
}
break;
}
this->release();
}
void ListView::interceptTouchEvent(TouchEventType event, Widget *sender, Touch* touch)

View File

@ -521,6 +521,7 @@ void PageView::interceptTouchEvent(TouchEventType event, Widget *sender, Touch *
void PageView::pageTurningEvent()
{
this->retain();
if (_pageViewEventListener && _pageViewEventSelector)
{
(_pageViewEventListener->*_pageViewEventSelector)(this, PAGEVIEW_EVENT_TURNING);
@ -528,6 +529,7 @@ void PageView::pageTurningEvent()
if (_eventCallback) {
_eventCallback(this,EventType::TURNING);
}
this->release();
}
void PageView::addEventListenerPageView(Ref *target, SEL_PageViewEvent selector)

View File

@ -1577,6 +1577,7 @@ void ScrollView::interceptTouchEvent(Widget::TouchEventType event, Widget *sende
void ScrollView::scrollToTopEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_TOP);
@ -1584,10 +1585,12 @@ void ScrollView::scrollToTopEvent()
if (_eventCallback) {
_eventCallback(this,EventType::SCROLL_TO_TOP);
}
this->release();
}
void ScrollView::scrollToBottomEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_BOTTOM);
@ -1595,10 +1598,12 @@ void ScrollView::scrollToBottomEvent()
if (_eventCallback) {
_eventCallback(this,EventType::SCROLL_TO_BOTTOM);
}
this->release();
}
void ScrollView::scrollToLeftEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_LEFT);
@ -1606,10 +1611,12 @@ void ScrollView::scrollToLeftEvent()
if (_eventCallback) {
_eventCallback(this,EventType::SCROLL_TO_LEFT);
}
this->release();
}
void ScrollView::scrollToRightEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLL_TO_RIGHT);
@ -1617,10 +1624,12 @@ void ScrollView::scrollToRightEvent()
if (_eventCallback) {
_eventCallback(this,EventType::SCROLL_TO_RIGHT);
}
this->release();
}
void ScrollView::scrollingEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_SCROLLING);
@ -1628,10 +1637,12 @@ void ScrollView::scrollingEvent()
if (_eventCallback) {
_eventCallback(this,EventType::SCROLLING);
}
this->release();
}
void ScrollView::bounceTopEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_TOP);
@ -1639,10 +1650,12 @@ void ScrollView::bounceTopEvent()
if (_eventCallback) {
_eventCallback(this,EventType::BOUNCE_TOP);
}
this->release();
}
void ScrollView::bounceBottomEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_BOTTOM);
@ -1650,10 +1663,12 @@ void ScrollView::bounceBottomEvent()
if (_eventCallback) {
_eventCallback(this,EventType::BOUNCE_BOTTOM);
}
this->release();
}
void ScrollView::bounceLeftEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_LEFT);
@ -1661,10 +1676,12 @@ void ScrollView::bounceLeftEvent()
if (_eventCallback) {
_eventCallback(this,EventType::BOUNCE_LEFT);
}
this->release();
}
void ScrollView::bounceRightEvent()
{
this->retain();
if (_scrollViewEventListener && _scrollViewEventSelector)
{
(_scrollViewEventListener->*_scrollViewEventSelector)(this, SCROLLVIEW_EVENT_BOUNCE_RIGHT);
@ -1672,6 +1689,7 @@ void ScrollView::bounceRightEvent()
if (_eventCallback) {
_eventCallback(this,EventType::BOUNCE_RIGHT);
}
this->release();
}
void ScrollView::addEventListenerScrollView(Ref *target, SEL_ScrollViewEvent selector)

View File

@ -407,6 +407,7 @@ void Slider::addEventListener(const ccSliderCallback& callback)
void Slider::percentChangedEvent()
{
this->retain();
if (_sliderEventListener && _sliderEventSelector)
{
(_sliderEventListener->*_sliderEventSelector)(this,SLIDER_PERCENTCHANGED);
@ -414,6 +415,7 @@ void Slider::percentChangedEvent()
if (_eventCallback) {
_eventCallback(this, EventType::ON_PERCENTAGE_CHANGED);
}
this->release();
}
int Slider::getPercent()const

View File

@ -632,6 +632,7 @@ void TextField::setDeleteBackward(bool deleteBackward)
void TextField::attachWithIMEEvent()
{
this->retain();
if (_textFieldEventListener && _textFieldEventSelector)
{
(_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_ATTACH_WITH_IME);
@ -639,10 +640,12 @@ void TextField::attachWithIMEEvent()
if (_eventCallback) {
_eventCallback(this, EventType::ATTACH_WITH_IME);
}
this->release();
}
void TextField::detachWithIMEEvent()
{
this->retain();
if (_textFieldEventListener && _textFieldEventSelector)
{
(_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_DETACH_WITH_IME);
@ -650,10 +653,12 @@ void TextField::detachWithIMEEvent()
if (_eventCallback) {
_eventCallback(this, EventType::DETACH_WITH_IME);
}
this->release();
}
void TextField::insertTextEvent()
{
this->retain();
if (_textFieldEventListener && _textFieldEventSelector)
{
(_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_INSERT_TEXT);
@ -661,10 +666,12 @@ void TextField::insertTextEvent()
if (_eventCallback) {
_eventCallback(this, EventType::INSERT_TEXT);
}
this->release();
}
void TextField::deleteBackwardEvent()
{
this->retain();
if (_textFieldEventListener && _textFieldEventSelector)
{
(_textFieldEventListener->*_textFieldEventSelector)(this, TEXTFIELD_EVENT_DELETE_BACKWARD);
@ -672,6 +679,7 @@ void TextField::deleteBackwardEvent()
if (_eventCallback) {
_eventCallback(this, EventType::DELETE_BACKWARD);
}
this->release();
}
void TextField::addEventListenerTextField(Ref *target, SEL_TextFieldEvent selecor)