fix memory leak when reload texture

This commit is contained in:
Eric Zhong 2014-10-20 10:43:18 +08:00
parent 84e0ae750c
commit fdd20b4d73
1 changed files with 4 additions and 1 deletions

View File

@ -406,6 +406,7 @@ Texture2D* TextureCache::addImage(Image *image, const std::string &key)
bool TextureCache::reloadTexture(const std::string& fileName) bool TextureCache::reloadTexture(const std::string& fileName)
{ {
Texture2D * texture = nullptr; Texture2D * texture = nullptr;
Image * image = nullptr;
std::string fullpath = FileUtils::getInstance()->fullPathForFilename(fileName); std::string fullpath = FileUtils::getInstance()->fullPathForFilename(fileName);
if (fullpath.size() == 0) if (fullpath.size() == 0)
@ -426,7 +427,7 @@ bool TextureCache::reloadTexture(const std::string& fileName)
else else
{ {
do { do {
Image* image = new (std::nothrow) Image(); image = new (std::nothrow) Image();
CC_BREAK_IF(nullptr == image); CC_BREAK_IF(nullptr == image);
bool bRet = image->initWithImageFile(fullpath); bool bRet = image->initWithImageFile(fullpath);
@ -436,6 +437,8 @@ bool TextureCache::reloadTexture(const std::string& fileName)
} while (0); } while (0);
} }
CC_SAFE_RELEASE(image);
return ret; return ret;
} }