cocos2d-x 弹出堆被损坏,这说明 **.win32.exe 中或它所加载的任何 DLL 中有 Bug的解决方法

在cocos2dx中定义数组变量,如

private: 
	cocos2d::CCArray *_Objs;
	cocos2d::CCArray *_Enemys;
	cocos2d::CCArray *_nogo;
	cocos2d::CCArray *_AllRoute;
	cocos2d::CCArray *_routesend;

如上,可以在构造函数里面定义初始化new CCArray,以及retain,在析构函数定义release。

Enemy::Enemy()
{
	_Enemys=new cocos2d::CCArray;
	_Objs=new cocos2d::CCArray;
	_AllRoute=new cocos2d::CCArray;
	_routesend=new cocos2d::CCArray;
	_nogo=new cocos2d::CCArray;

	//这里注意要retain
}
在其中发现一个问题,在我选择在Parent父层传来的_Objs我接收之后

在父类调用enemy->getObjs(array);

如果在析构函数要释放掉_Objs是会出现一下图

cocos2d-x 弹出堆被损坏,这说明 **.win32.exe 中或它所加载的任何 DLL 中有 Bug的解决方法_第1张图片
其解决方法就是在析构函数里面注销掉_Objs,所以大家遇到这问题就在析构函数里面找原因吧

Enemy::~Enemy()
{
	this->unscheduleAllSelectors();	
	_routesend->release();
	_AllRoute->release();
	//传过来没赋值的障碍物数组释放不了,是外部付值释放不了,不安全的意思
/*	_Objs->release();*/
	_Enemys->release();
	_nogo->release();

}




你可能感兴趣的:(cocos2dx数组问题)