码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2dx 2.2.5 hitWidget->onTouchEnded(pTouch, pEvent); 异常

时间:2014-09-15 15:50:19      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:io   os   ar   for   问题   on   c   r   ui   

源码:extensions\CocoStudio\GUI\System\UITouchGroup.cpp

void TouchGroup::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
ccArray* selectedWidgetArray = m_pSelectedWidgets->data;
int length = selectedWidgetArray->num;
for (int i=0; i<length; ++i)
{
Widget* hitWidget = (Widget*)(selectedWidgetArray->arr[0]);
m_pSelectedWidgets->removeObject(hitWidget);

hitWidget->onTouchEnded(pTouch, pEvent);   ---------这一行异常
}
}

异常发生后,查看变量信息,发现hitWidget有些信息已经被释放了,再看看hitWidget->onTouchEnded(pTouch, pEvent);这句之前是removeObject,想着有可能是removeObject中把hitWidget的部分内容给释放,所以,改为

void TouchGroup::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
ccArray* selectedWidgetArray = m_pSelectedWidgets->data;
int length = selectedWidgetArray->num;
for (int i=0; i<length; ++i)
{
Widget* hitWidget = (Widget*)(selectedWidgetArray->arr[0]);

hitWidget->onTouchEnded(pTouch, pEvent);

m_pSelectedWidgets->removeObject(hitWidget);

}
}

scroll中滚动再没出现过该异常。希望这个解决方案是正确的,如有问题,请指正。

cocos2dx 2.2.5 hitWidget->onTouchEnded(pTouch, pEvent); 异常

标签:io   os   ar   for   问题   on   c   r   ui   

原文地址:http://www.cnblogs.com/playerboy/p/3972834.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!