Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory leaking and avoid crash at RenderTexture #20531

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions cocos/2d/CCRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,10 @@ bool RenderTexture::initWithWidthAndHeight(int w, int h, backend::PixelFormat fo
texture->release();
}
else
{
texture->release();
break;
}

_renderTargetFlags = RenderTargetFlag::COLOR;

Expand Down Expand Up @@ -475,10 +478,11 @@ void RenderTexture::newImage(std::function<void(Image*)> imageCallback, bool fli
int savedBufferWidth = (int)s.width;
int savedBufferHeight = (int)s.height;

bool hasPremultipliedAlpha = _texture2D->hasPremultipliedAlpha();
Image *image = new (std::nothrow) Image();
auto initCallback = [&, savedBufferWidth, savedBufferHeight, imageCallback](Image* image, const unsigned char* tempData){
image->initWithRawData(tempData, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8, _texture2D->hasPremultipliedAlpha());

auto initCallback = [savedBufferWidth, savedBufferHeight, hasPremultipliedAlpha, imageCallback](Image* image, const unsigned char* tempData){
image->initWithRawData(tempData, savedBufferWidth * savedBufferHeight * 4, savedBufferWidth, savedBufferHeight, 8, hasPremultipliedAlpha);
imageCallback(image);
};
auto callback = std::bind(initCallback, image, std::placeholders::_1);
Expand Down