fixed #1597: Added return pointer check.

This commit is contained in:
James Chen 2012-12-27 16:07:48 +08:00
parent ac7755e68b
commit b62d254f63
3 changed files with 12 additions and 10 deletions

View File

@ -47,6 +47,7 @@ static CCTexture2D* getDefaultTexture()
CC_BREAK_IF(pTexture != NULL);
pImage = new CCImage();
CC_BREAK_IF(NULL == pImage);
bRet = pImage->initWithImageData((void*)__firePngData, sizeof(__firePngData), CCImage::kFmtPng);
CC_BREAK_IF(!bRet);

View File

@ -427,8 +427,6 @@ bool CCTexture2D::initWithString(const char *text, const char *fontName, float f
#endif
bool bRet = false;
CCImage* pImage = new CCImage();
CCImage::ETextAlign eAlign;
if (kCCVerticalTextAlignmentTop == vAlignment)
@ -453,13 +451,14 @@ bool CCTexture2D::initWithString(const char *text, const char *fontName, float f
do
{
CCImage* pImage = new CCImage();
CC_BREAK_IF(NULL == pImage);
bRet = pImage->initWithString(text, (int)dimensions.width, (int)dimensions.height, eAlign, fontName, (int)fontSize);
CC_BREAK_IF(!bRet);
bRet = initWithImage(pImage);
CC_SAFE_RELEASE(pImage);
} while (0);
CC_SAFE_RELEASE(pImage);
return bRet;
}

View File

@ -159,9 +159,9 @@ static void* loadImage(void* data)
// generate image
CCImage *pImage = new CCImage();
if (! pImage->initWithImageFileThreadSafe(filename, imageType))
if (pImage && !pImage->initWithImageFileThreadSafe(filename, imageType))
{
pImage->release();
CC_SAFE_RELEASE(pImage);
CCLOG("can not load %s", filename);
continue;
}
@ -435,7 +435,9 @@ CCTexture2D * CCTextureCache::addImage(const char * path)
eImageFormat = CCImage::kFmtTiff;
}
pImage = new CCImage();
pImage = new CCImage();
CC_BREAK_IF(NULL == pImage);
unsigned long nSize = 0;
unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullpath.c_str(), "rb", &nSize);
bool bRet = pImage->initWithImageData((void*)pBuffer, nSize, eImageFormat);
@ -853,7 +855,6 @@ void VolatileTexture::reloadAllTextures()
{
case kImageFile:
{
CCImage* pImage = new CCImage();
std::string lowerCase(vt->m_strFileName.c_str());
for (unsigned int i = 0; i < lowerCase.length(); ++i)
{
@ -870,10 +871,11 @@ void VolatileTexture::reloadAllTextures()
}
else
{
CCImage* pImage = new CCImage();
unsigned long nSize = 0;
unsigned char* pBuffer = CCFileUtils::sharedFileUtils()->getFileData(vt->m_strFileName.c_str(), "rb", &nSize);
if (pImage->initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
if (pImage && pImage->initWithImageData((void*)pBuffer, nSize, vt->m_FmtImage))
{
CCTexture2DPixelFormat oldPixelFormat = CCTexture2D::defaultAlphaPixelFormat();
CCTexture2D::setDefaultAlphaPixelFormat(vt->m_PixelFormat);
@ -882,8 +884,8 @@ void VolatileTexture::reloadAllTextures()
}
CC_SAFE_DELETE_ARRAY(pBuffer);
CC_SAFE_RELEASE(pImage);
}
CC_SAFE_RELEASE(pImage);
}
break;
case kImageData: