From cda47ac219b430775965a263c0ec1b16f2f42906 Mon Sep 17 00:00:00 2001 From: monoliths Date: Tue, 18 Jul 2023 21:39:53 +0800 Subject: [PATCH] Fix: Null Image Data In RenderTexture::newImage Callback Error(#20776) --- cocos/2d/CCRenderTexture.cpp | 7 +++++++ cocos/2d/CCRenderTexture.h | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cocos/2d/CCRenderTexture.cpp b/cocos/2d/CCRenderTexture.cpp index c7bdcf75993b..b21b2210fe6a 100644 --- a/cocos/2d/CCRenderTexture.cpp +++ b/cocos/2d/CCRenderTexture.cpp @@ -501,6 +501,13 @@ void RenderTexture::newImage(std::function imageCallback, bool fli // } while (0); } +void RenderTexture::createNewImage(std::function 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) diff --git a/cocos/2d/CCRenderTexture.h b/cocos/2d/CCRenderTexture.h index c8c888793e1b..7134ce46d2a8 100644 --- a/cocos/2d/CCRenderTexture.h +++ b/cocos/2d/CCRenderTexture.h @@ -159,6 +159,15 @@ class CC_DLL RenderTexture : public Node * @js NA */ void newImage(std::function 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 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. @@ -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 _saveFileCallback = nullptr; Mat4 _oldTransMatrix, _oldProjMatrix;