Bug #484

CCTextureAtlas::initWithTexture() may cause memory leak

Added by Minggo Zhang about 2 years ago. Updated 12 months ago.

Status:Closed Start date:2011-05-06
Priority:Normal Due date:
Assignee:Minggo Zhang % Done:

100%

Category:-
Target version:-

Description

bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity) {
assert(texture != NULL);
m_uCapacity = capacity;
m_uTotalQuads = 0;

// retained in property
this->m_pTexture = texture;
CC_SAFE_RETAIN(m_pTexture);
m_pQuads = (ccV3F_C4B_T2F_Quad*)calloc( sizeof(ccV3F_C4B_T2F_Quad) * m_uCapacity, 1 );
m_pIndices = (GLushort *)calloc( sizeof(GLushort) * m_uCapacity * 6, 1 );
if( ! ( m_pQuads && m_pIndices) ) {
//CCLOG("cocos2d: CCTextureAtlas: not enough memory");
CC_SAFE_FREE(m_pQuads)
CC_SAFE_FREE(m_pIndices)
return false;
}

When the condition in if sentence is true, should release the texture. Because the destructure will release it, so should use CC_SAFE_RELEASE_NULL() to release it.

History

Updated by Zhe Wang about 2 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

Applied in changeset commit:7cd52b11452e99982379a142dd9dad771b9b7922.

Updated by Minggo Zhang about 2 years ago

Applied in changeset commit:e93c06bb70038cb577e340b6ee1aab95cb576f48.

Updated by Zhe Wang about 2 years ago

  • Status changed from Resolved to Closed

Updated by Zhe Wang 12 months ago

  • Project changed from cocos2d-x to native
  • Category deleted (5)
  • Target version deleted (cocos2d-0.99.5-x-0.8.3)

Also available in: Atom PDF