From dd675f8cf12b66c989df6fae840dc0834dc3bf0a Mon Sep 17 00:00:00 2001 From: natural-law Date: Fri, 11 Mar 2011 17:41:19 +0800 Subject: [PATCH] [wophone]Resolve the memory leak of CCAccelerometer. --- .../platform/wophone/CCAccelerometer_wophone.cpp | 16 ++++++++++++++++ cocos2dx/sprite_nodes/CCSprite.cpp | 7 +------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/cocos2dx/platform/wophone/CCAccelerometer_wophone.cpp b/cocos2dx/platform/wophone/CCAccelerometer_wophone.cpp index cf9c7c7525..d7ffa388b8 100644 --- a/cocos2dx/platform/wophone/CCAccelerometer_wophone.cpp +++ b/cocos2dx/platform/wophone/CCAccelerometer_wophone.cpp @@ -147,6 +147,22 @@ void CCAccelerometer::removeDelegate(CCAccelerometerDelegate* pDelegate) void CCAccelerometer::addDelegate(CCAccelerometerDelegate* pDelegate) { + CCAccelerometerHandler *pHandlerIter; + CCMutableArray::CCMutableArrayIterator iter; + + if (pDelegate) + { + for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter) + { + pHandlerIter = *iter; + if (pHandlerIter && pHandlerIter->getDelegate() == pDelegate) + { + // this delegate have existed + return; + } + } + } + CCAccelerometerHandler* pHandler = CCAccelerometerHandler::handlerWithDelegate(pDelegate); if (pHandler) diff --git a/cocos2dx/sprite_nodes/CCSprite.cpp b/cocos2dx/sprite_nodes/CCSprite.cpp index 33ed8b3f32..e27a08d88f 100644 --- a/cocos2dx/sprite_nodes/CCSprite.cpp +++ b/cocos2dx/sprite_nodes/CCSprite.cpp @@ -978,12 +978,7 @@ void CCSprite::setDisplayFrame(CCSpriteFrame *pNewFrame) CCTexture2D *pNewTexture = pNewFrame->getTexture(); // update texture before updating texture rect - if ((pNewTexture && m_pobTexture) && - (pNewTexture->getName() == m_pobTexture->getName())) - { - // new texture is same with the current texture,nothing to do - } - else + if (pNewTexture != m_pobTexture) { setTexture(pNewTexture); }