diff --git a/native/cocos/2d/CCSprite.cpp b/native/cocos/2d/CCSprite.cpp index ad843ea349..32eadbae56 100644 --- a/native/cocos/2d/CCSprite.cpp +++ b/native/cocos/2d/CCSprite.cpp @@ -359,14 +359,24 @@ void Sprite::setTexture(Texture2D *texture) if (texture == nullptr) { Image* image = new (std::nothrow) Image(); - bool isOK = image->initWithRawData(cc_2x2_white_image, sizeof(cc_2x2_white_image), 2, 2, 8); - CC_UNUSED_PARAM(isOK); - CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully."); - - texture = _director->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); - CC_SAFE_RELEASE(image); + if(image) + { + bool isOK = image->initWithRawData(cc_2x2_white_image, sizeof(cc_2x2_white_image), 2, 2, 8); + CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully."); + if (isOK) + texture = _director->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); + + image->release(); + } } } + + CCASSERT(texture, "texture should not nullptr!"); + if(texture == nullptr) + { + log("Sprite::setTexture error:texture should not nullptr!"); + return; + } if (!_batchNode && _texture != texture) { diff --git a/native/cocos/network/HttpClient-android.cpp b/native/cocos/network/HttpClient-android.cpp index 4891c39e9e..2e3efa5250 100644 --- a/native/cocos/network/HttpClient-android.cpp +++ b/native/cocos/network/HttpClient-android.cpp @@ -892,7 +892,7 @@ HttpClient::HttpClient() HttpClient::~HttpClient() { CCLOG("In the destructor of HttpClient!"); - CC_SAFE_DELETE(_requestSentinel); + CC_SAFE_RELEASE(_requestSentinel); } //Lazy create semaphore & mutex & thread diff --git a/native/cocos/network/HttpClient-apple.mm b/native/cocos/network/HttpClient-apple.mm index 5f02256e18..397d159761 100644 --- a/native/cocos/network/HttpClient-apple.mm +++ b/native/cocos/network/HttpClient-apple.mm @@ -371,7 +371,7 @@ HttpClient::HttpClient() HttpClient::~HttpClient() { - CC_SAFE_DELETE(_requestSentinel); + CC_SAFE_RELEASE(_requestSentinel); if (!_cookieFilename.empty() && nullptr != _cookie) { _cookie->writeFile(); diff --git a/native/cocos/network/HttpClient.cpp b/native/cocos/network/HttpClient.cpp index 085091e769..956628ab91 100644 --- a/native/cocos/network/HttpClient.cpp +++ b/native/cocos/network/HttpClient.cpp @@ -411,7 +411,7 @@ HttpClient::HttpClient() HttpClient::~HttpClient() { - CC_SAFE_DELETE(_requestSentinel); + CC_SAFE_RELEASE(_requestSentinel); CCLOG("HttpClient destructor"); } diff --git a/native/cocos/network/WebSocket.cpp b/native/cocos/network/WebSocket.cpp index 524bafc127..85182f2a6b 100644 --- a/native/cocos/network/WebSocket.cpp +++ b/native/cocos/network/WebSocket.cpp @@ -600,12 +600,11 @@ void WebSocket::onSubThreadStarted() if (_wsProtocols[i+1].callback != nullptr) name += ", "; } - char portStr[10]; - sprintf(portStr, "%d", _port); - std::string ads_port = _host + ":" + portStr; + char ads_port[50]; + sprintf(ads_port, "%s:%d", _host.c_str(), _port); lws_client_connect_info cInfo = {_wsContext, _host.c_str(), (int)_port, _SSLConnection, - _path.c_str(), ads_port.c_str(), ads_port.c_str(), + _path.c_str(), ads_port, _host.c_str(), name.c_str(), -1,nullptr,nullptr}; _wsInstance = lws_client_connect_via_info(&cInfo);