Skip to content

Commit fa3ab72

Browse files
dumganharminggo
authored andcommitted
Fix memory leak if invoking Texture2D::setAlphaTexture many times. (#19400)
1 parent 4db6353 commit fa3ab72

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

cocos/renderer/CCTexture2D.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,10 +1499,12 @@ void Texture2D::removeSpriteFrameCapInset(SpriteFrame* spriteFrame)
14991499
/// halx99 spec, ANDROID ETC1 ALPHA supports.
15001500
void Texture2D::setAlphaTexture(Texture2D* alphaTexture)
15011501
{
1502-
if (alphaTexture != nullptr) {
1503-
this->_alphaTexture = alphaTexture;
1504-
this->_alphaTexture->retain();
1505-
this->_hasPremultipliedAlpha = true; // PremultipliedAlpha should be true.
1502+
if (alphaTexture != nullptr)
1503+
{
1504+
alphaTexture->retain();
1505+
CC_SAFE_RELEASE(_alphaTexture);
1506+
_alphaTexture = alphaTexture;
1507+
_hasPremultipliedAlpha = true; // PremultipliedAlpha should be true.
15061508
}
15071509
}
15081510

0 commit comments

Comments
 (0)