Skip to content

Commit cb22de5

Browse files
committed
Merge pull request #14590 from pandemosth/issue_14589
Fixes #14589 allocation issue with remote images
2 parents ab45a69 + 54ac5d8 commit cb22de5

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,16 +872,19 @@ void __JSDownloaderDelegator::startDownload()
872872
_downloader->onDataTaskSuccess = [this](const cocos2d::network::DownloadTask& task,
873873
std::vector<unsigned char>& data)
874874
{
875-
Image img;
875+
Image* img = new (std::nothrow) Image();
876876
Texture2D *tex = nullptr;
877877
do
878878
{
879-
if (false == img.initWithImageData(data.data(), data.size()))
879+
if (false == img->initWithImageData(data.data(), data.size()))
880880
{
881881
break;
882882
}
883-
tex = Director::getInstance()->getTextureCache()->addImage(&img, _url);
883+
tex = Director::getInstance()->getTextureCache()->addImage(img, _url);
884884
} while (0);
885+
886+
CC_SAFE_RELEASE(img);
887+
885888
if (tex)
886889
{
887890
this->onSuccess(tex);

0 commit comments

Comments
 (0)