mirror of https://github.com/axmolengine/axmol.git
fixed texture memory leak and added comments to indicate problem
This commit is contained in:
parent
65400bf87b
commit
294341d0ab
|
@ -185,7 +185,9 @@ void FontAtlas::listenToForeground(EventCustom *event)
|
|||
auto contentSize = Size(CacheTextureWidth,CacheTextureHeight);
|
||||
auto pixelFormat = fontTTf->getOutlineSize() > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8;
|
||||
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, contentSize );
|
||||
// this is a memory leak as the texture previously in _atlasTextures[_currentPage] is not deleted from OpenGL
|
||||
// see CCTexture2D::initWithData for the temporary fix
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, contentSize );
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -254,8 +256,10 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
_currentPageOrigY += _commonLineHeight;
|
||||
_currentPageOrigX = 0;
|
||||
if(_currentPageOrigY + _commonLineHeight >= CacheTextureHeight)
|
||||
{
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, contentSize );
|
||||
{
|
||||
// this is a memory leak as the texture previously in _atlasTextures[_currentPage] is not deleted from OpenGL
|
||||
// see CCTexture2D::initWithData for the temporary fix
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, contentSize );
|
||||
_currentPageOrigY = 0;
|
||||
memset(_currentPageData, 0, _currentPageDataSize);
|
||||
_currentPage++;
|
||||
|
@ -299,6 +303,8 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String)
|
|||
|
||||
if(existNewLetter)
|
||||
{
|
||||
// this is a memory leak as the texture previously in _atlasTextures[_currentPage] is not deleted from OpenGL
|
||||
// see CCTexture2D::initWithData for the temporary fix
|
||||
_atlasTextures[_currentPage]->initWithData(_currentPageData, _currentPageDataSize, pixelFormat, CacheTextureWidth, CacheTextureHeight, contentSize );
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -51,6 +51,8 @@ THE SOFTWARE.
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
|
||||
|
||||
namespace {
|
||||
typedef Texture2D::PixelFormatInfoMap::value_type PixelFormatInfoMapValue;
|
||||
static const PixelFormatInfoMapValue TexturePixelFormatInfoTablesValue[] =
|
||||
|
@ -533,6 +535,15 @@ bool Texture2D::hasPremultipliedAlpha() const
|
|||
|
||||
bool Texture2D::initWithData(const void *data, ssize_t dataLen, Texture2D::PixelFormat pixelFormat, int pixelsWide, int pixelsHigh, const Size& contentSize)
|
||||
{
|
||||
// cocos2d-x is currently calling this multiple times on the same Texture2D
|
||||
// if the GL texture has already been created,it will be leaked in OpenGL
|
||||
// For now, call deleteTexture if the texture already exists
|
||||
if(_name)
|
||||
{
|
||||
GL::deleteTexture(_name);
|
||||
_name = 0;
|
||||
}
|
||||
|
||||
CCASSERT(dataLen>0 && pixelsWide>0 && pixelsHigh>0, "Invalid size");
|
||||
|
||||
//if data has no mipmaps, we will consider it has only one mipmap
|
||||
|
|
Loading…
Reference in New Issue