Skip to content

Commit

Permalink
fixed #628, CCMutableArray::arrayWithObjects & arrayWithArray should …
Browse files Browse the repository at this point in the history
…set the return object to autorelease. And add CCAnimation::m_pobFrames->retain() after it get value from arrayWithArray. (it's property with retain in -iphone version but we miss the retain)
  • Loading branch information
Walzer committed Jul 24, 2011
1 parent 3df9bc3 commit 2038ead
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 14 additions & 5 deletions cocos2dx/include/CCMutableArray.h
Expand Up @@ -369,6 +369,7 @@ class CCMutableArray : public CCObject
static CCMutableArray<T>* arrayWithObjects(T pObject1, ...)
{
CCMutableArray<T> *pArray = new CCMutableArray<T>();
pArray->autorelease();

va_list params;
va_start(params, pObject1);
Expand All @@ -385,14 +386,22 @@ class CCMutableArray : public CCObject
return pArray;
}

static CCMutableArray<T>* arrayWithArray(CCMutableArray<T> *pArray)
static CCMutableArray<T>* arrayWithArray(CCMutableArray<T> *pSrcArray)
{
if (pArray == NULL)
CCMutableArray<T> *pDestArray = NULL;

if (pSrcArray == NULL)
{
return new CCMutableArray<T>();
pDestArray = new CCMutableArray<T>();
}

return pArray->copy();
else
{
pDestArray = pSrcArray->copy();
}

pDestArray->autorelease();

return pDestArray;
}

private:
Expand Down
4 changes: 3 additions & 1 deletion cocos2dx/sprite_nodes/CCAnimation.cpp
Expand Up @@ -105,7 +105,8 @@ namespace cocos2d
{
m_fDelay = delay;
m_pobFrames = CCMutableArray<CCSpriteFrame*>::arrayWithArray(pFrames);

m_pobFrames->retain();

return true;
}

Expand Down Expand Up @@ -134,6 +135,7 @@ namespace cocos2d
m_fDelay = fDelay;
m_nameStr = pszName;
m_pobFrames = CCMutableArray<CCSpriteFrame*>::arrayWithArray(pFrames);
m_pobFrames->retain();

return true;
}
Expand Down

0 comments on commit 2038ead

Please sign in to comment.