cocos2d-x例子里的bug,哪位大神能修复一下

ActionTest里面的PauseResumeActions

void PauseResumeActions::pause(float dt)
{
    CCLog("Pausing");
    CCDirector *director = CCDirector::sharedDirector();
    this->m_pPausedTargets = director->getActionManager()->pauseAllRunningActions();
}

void PauseResumeActions::resume(float dt)
{
    CCLog("Resuming");
    CCDirector *director = CCDirector::sharedDirector();
    director->getActionManager()->resumeTargets(this->m_pPausedTargets);
}

里面的this->m_pPausedTargets好像被后台delete了,导致在resumeTargets里没法读取暂停的对象列表。
这是例子程序,大家都有,看看是不是也报错?

— Begin quote from ____

juckerpp 发表于 2012-8-15 14:41 url

自己修复了- -0 ,把返回的列表我们自己管理就好。。
fix code:
这样就不会报错了。。。看来cocos2d-x后面 …

— End quote

不是不完善,而是你这里这样写的问题。

首先,coco2d里面所有的对象引用都要加入引用计数的,你这里让管理器返回一个对象列表,但是没有retain,但是又是全局变量。在下次使用的时候难免有的被释放。
如果你都加一次retain就不存在了。

自己修复了- -0 ,把返回的列表我们自己管理就好。。
fix code:

void CGameManager::PauseGame()
{
	bPaused = true;
	CDTimeManager::getInstance()->PauseStartTime = millisecondNow();
	CCSet * tempPuaseList  = CCDirector::sharedDirector()->getActionManager()->pauseAllRunningActions();

	m_lastPauseAction = new CCSet;
	CCSetIterator iter = tempPuaseList->begin();
	for(; iter != tempPuaseList->end(); iter++)
	{
		m_lastPauseAction->addObject(*iter);
	}

	m_GameStatus = enGame_Pause;
}

void CGameManager::ResumeGame()
{
	bPaused = false;
	CDTimeManager::getInstance()->CalcSubTime();
	
	m_GameStatus = enGame_Playing;

	//clear m_lastPauseAction
	CCDirector::sharedDirector()->getActionManager()->resumeTargets(this->m_lastPauseAction);
	delete m_lastPauseAction;
	
}

这样就不会报错了。。。看来cocos2d-x后面的内存管理机制还不是那么的完善。。尤其是retain那个玩意