From e399a7736926439ca8c60995b4425927d229e63e Mon Sep 17 00:00:00 2001 From: walzer Date: Mon, 17 Jan 2011 22:01:15 +0800 Subject: [PATCH] fixed #306, invoke CCDirector::end() method in next msgloop, otherwise the flow will crashes when end() is called in an ActionInterval. --- cocos2dx/include/CCDirector.h | 2 ++ cocos2dx/platform/CCDirector_mobile.cpp | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/cocos2dx/include/CCDirector.h b/cocos2dx/include/CCDirector.h index 93d555ae11..7234ba15c4 100644 --- a/cocos2dx/include/CCDirector.h +++ b/cocos2dx/include/CCDirector.h @@ -459,6 +459,8 @@ protected: * mobile platforms specific functions **************************************************/ void purgeDirector(); + bool m_bPurgeDirecotorInNextLoop; // this flag will be set to true in end() + bool isOpenGLAttached(void); void updateContentScaleFactor(void); diff --git a/cocos2dx/platform/CCDirector_mobile.cpp b/cocos2dx/platform/CCDirector_mobile.cpp index ee44d08045..d4ed8abcfd 100644 --- a/cocos2dx/platform/CCDirector_mobile.cpp +++ b/cocos2dx/platform/CCDirector_mobile.cpp @@ -106,6 +106,9 @@ bool CCDirector::init(void) // paused ? m_bPaused = false; + + // purge ? + m_bPurgeDirecotorInNextLoop = false; m_obWinSizeInPixels = m_obWinSizeInPoints = CGSizeZero; @@ -126,7 +129,7 @@ bool CCDirector::init(void) return true; } - + CCDirector::~CCDirector(void) { CCLOGINFO("cocos2d: deallocing %p", this); @@ -535,7 +538,12 @@ void CCDirector::popScene(void) } } -void CCDirector::end(void) +void CCDirector::end() +{ + m_bPurgeDirecotorInNextLoop = true; +} + +void CCDirector::purgeDirector() { // don't release the event handlers // They are needed in case the director is run again @@ -926,7 +934,11 @@ void CCDisplayLinkDirector::startAnimation(void) void CCDisplayLinkDirector::mainLoop(void) { - if (! m_bInvalid) + if (m_bPurgeDirecotorInNextLoop) + { + purgeDirector(); + } + else if (! m_bInvalid) { drawScene();