Fix memory leak if invoking Texture2D::setAlphaTexture many times. (#19590)

This commit is contained in:
minggo 2019-04-10 01:53:29 -07:00 committed by GitHub
parent 195dc704e3
commit bc1483dca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -897,9 +897,10 @@ void Texture2D::removeSpriteFrameCapInset(SpriteFrame* spriteFrame)
void Texture2D::setAlphaTexture(Texture2D* alphaTexture)
{
if (alphaTexture != nullptr) {
this->_alphaTexture = alphaTexture;
this->_alphaTexture->retain();
this->_hasPremultipliedAlpha = true; // PremultipliedAlpha should be true.
alphaTexture->retain();
CC_SAFE_RELEASE(_alphaTexture);
_alphaTexture = alphaTexture;
_hasPremultipliedAlpha = true; // PremultipliedAlpha should be true.
}
}