Skip to content

Commit

Permalink
Fix: Null Image Data In RenderTexture::newImage Callback Error(cocos2…
Browse files Browse the repository at this point in the history
  • Loading branch information
Diam2023 committed Jul 18, 2023
1 parent 44c14c7 commit cda47ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cocos/2d/CCRenderTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ void RenderTexture::newImage(std::function<void(Image*)> imageCallback, bool fli
// } while (0);
}

void RenderTexture::createNewImage(std::function<void(Image*)> imageCallback, bool flipImage)
{
_newImageCommand.init(_globalZOrder);
_newImageCommand.func = CC_CALLBACK_0(RenderTexture::newImage, this, imageCallback, flipImage);
Director::getInstance()->getRenderer()->addCommand(&_newImageCommand);
}

void RenderTexture::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
if (_autoDraw)
Expand Down
15 changes: 15 additions & 0 deletions cocos/2d/CCRenderTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,15 @@ class CC_DLL RenderTexture : public Node
* @js NA
*/
void newImage(std::function<void(Image*)> imageCallback, bool flipImage = true);

/**
* New Version Of Create a new Image from with the texture's data.
* FIX: Null Image Data In RenderTexture::newImage Callback Issue (#20776)
*
* @param imageCallback
* @param flipImage
*/
void createNewImage(std::function<void(Image*)> imageCallback, bool flipImage = true);

/** Saves the texture into a file using JPEG format. The file will be saved in the Documents folder.
* Returns true if the operation is successful.
Expand Down Expand Up @@ -390,6 +399,12 @@ class CC_DLL RenderTexture : public Node
and the command and callback will be executed twice.
*/
CallbackCommand _saveToFileCommand;

/**
* This Command Use to Fix Null Image Data In RenderTexture::newImage(#20776)
*/
CallbackCommand _newImageCommand;

std::function<void (RenderTexture*, const std::string&)> _saveFileCallback = nullptr;

Mat4 _oldTransMatrix, _oldProjMatrix;
Expand Down

0 comments on commit cda47ac

Please sign in to comment.