mirror of https://github.com/axmolengine/axmol.git
fix memory leak when reload texture
This commit is contained in:
parent
84e0ae750c
commit
fdd20b4d73
|
@ -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);
|
||||||
|
@ -435,6 +436,8 @@ bool TextureCache::reloadTexture(const std::string& fileName)
|
||||||
ret = texture->initWithImage(image);
|
ret = texture->initWithImage(image);
|
||||||
} while (0);
|
} while (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CC_SAFE_RELEASE(image);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue