Fix RenderTexture memory leak and increased memory usage when initWithWidthAndHeight is called (#1191)

This commit is contained in:
RH 2023-04-28 16:54:57 +10:00 committed by GitHub
parent 697fd0fac7
commit 98146f438b
1 changed files with 8 additions and 1 deletions

View File

@ -198,6 +198,8 @@ bool RenderTexture::initWithWidthAndHeight(int w,
_renderTargetFlags = RenderTargetFlag::ALL; _renderTargetFlags = RenderTargetFlag::ALL;
descriptor.textureFormat = PixelFormat::D24S8; descriptor.textureFormat = PixelFormat::D24S8;
AX_SAFE_RELEASE(_depthStencilTexture);
_depthStencilTexture = new Texture2D(); _depthStencilTexture = new Texture2D();
_depthStencilTexture->updateTextureDescriptor(descriptor); _depthStencilTexture->updateTextureDescriptor(descriptor);
} }
@ -271,8 +273,13 @@ void RenderTexture::setSprite(Sprite* sprite)
sEngine->releaseScriptObject(this, _sprite); sEngine->releaseScriptObject(this, _sprite);
} }
#endif // AX_ENABLE_GC_FOR_NATIVE_OBJECTS #endif // AX_ENABLE_GC_FOR_NATIVE_OBJECTS
if (_sprite)
{
_sprite->removeFromParent();
_sprite->release();
}
AX_SAFE_RETAIN(sprite); AX_SAFE_RETAIN(sprite);
AX_SAFE_RELEASE(_sprite);
_sprite = sprite; _sprite = sprite;
} }