diff --git a/cocos/2d/CCAutoPolygon.cpp b/cocos/2d/CCAutoPolygon.cpp index bea7bd57b5..8c59523cd1 100644 --- a/cocos/2d/CCAutoPolygon.cpp +++ b/cocos/2d/CCAutoPolygon.cpp @@ -253,7 +253,6 @@ std::vector AutoPolygon::marchSquare(const Rect& rect, const Vec2 int curx = startx; int cury = starty; unsigned int count = 0; - unsigned int totalPixel = _width*_height; bool problem = false; std::vector case9s; std::vector case6s; @@ -408,7 +407,11 @@ std::vector AutoPolygon::marchSquare(const Rect& rect, const Vec2 prevx = stepx; prevy = stepy; problem = false; + +#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0) + const auto totalPixel = _width * _height; CCASSERT(count <= totalPixel, "oh no, marching square cannot find starting position"); +#endif } while(curx != startx || cury != starty); return _points; } diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index 1b3cd03c4b..96047c7c75 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -326,6 +326,11 @@ Sprite* createSpriteFromBase64Cached(const char* base64String, const char* key) CCASSERT(imageResult, "Failed to create image from base64!"); free(decoded); + if (!imageResult) { + CC_SAFE_RELEASE_NULL(image); + return nullptr; + } + texture = Director::getInstance()->getTextureCache()->addImage(image, key); image->release(); } @@ -345,6 +350,11 @@ Sprite* createSpriteFromBase64(const char* base64String) CCASSERT(imageResult, "Failed to create image from base64!"); free(decoded); + if (!imageResult) { + CC_SAFE_RELEASE_NULL(image); + return nullptr; + } + Texture2D *texture = new (std::nothrow) Texture2D(); texture->initWithImage(image); texture->setAliasTexParameters();