Skip to content

Commit bc1483d

Browse files
author
minggo
authored
Fix memory leak if invoking Texture2D::setAlphaTexture many times. (#19590)
1 parent 195dc70 commit bc1483d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cocos/renderer/CCTexture2D.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -897,9 +897,10 @@ void Texture2D::removeSpriteFrameCapInset(SpriteFrame* spriteFrame)
897897
void Texture2D::setAlphaTexture(Texture2D* alphaTexture)
898898
{
899899
if (alphaTexture != nullptr) {
900-
this->_alphaTexture = alphaTexture;
901-
this->_alphaTexture->retain();
902-
this->_hasPremultipliedAlpha = true; // PremultipliedAlpha should be true.
900+
alphaTexture->retain();
901+
CC_SAFE_RELEASE(_alphaTexture);
902+
_alphaTexture = alphaTexture;
903+
_hasPremultipliedAlpha = true; // PremultipliedAlpha should be true.
903904
}
904905
}
905906

0 commit comments

Comments
 (0)