Skip to content

Commit

Permalink
fix memory leaking and avoid crash at RenderTexture
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongfq committed Jun 28, 2020
1 parent 42dd179 commit 92a9238
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions frameworks/cocos2d-x/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 @@ -474,11 +477,11 @@ void RenderTexture::newImage(std::function<void(Image*)> imageCallback, bool fli
// it should be cut
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

0 comments on commit 92a9238

Please sign in to comment.