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: Null Image Data In RenderTexture::newImage Callback Error(#20776) #20777

Open
wants to merge 1 commit into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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