diff --git a/CHANGELOG b/CHANGELOG index 725848627c..b8154738f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -5,6 +5,7 @@ cocos2d-x-3.10 December ? 2015 [NEW] UI: UIText::clone supports clone the text effect. [NEW] Label: Add methods to query label effect state. +[REFINE] UI: Slider `setCapInsetProgressBarRebderer` change to `setCapInsetProgressBarRenderer`. [REFINE] UI: RichText support new line element. [REFINE] UI: Set focus to Widget when touched. [REFINE] UI: Change PageView to derived from ListView. @@ -14,6 +15,7 @@ cocos2d-x-3.10 December ? 2015 [REFINE] Mac: Make engine compatible for 32bit Mac. [REFINE] Audio: AudioEngine on Linux replace the original SimpleAudioEngine with a new version of FMOD, now AudioEngine support all platforms! +[FIX] Network: fix possible websocket crash in its destructor. [FIX] Core: Fix premultiplyAlpha for mipmaps and compressed textures. [FIX] UI: Fix Scale9sprite rendering error when content size smaller than the sum of leftInset and rightInset. [FIX] Win32: Fix EditBox crash when removing an EditBox in a scheduler. diff --git a/cocos/2d/CCActionCatmullRom.cpp b/cocos/2d/CCActionCatmullRom.cpp index bbaea585f2..c2ca77a3e1 100644 --- a/cocos/2d/CCActionCatmullRom.cpp +++ b/cocos/2d/CCActionCatmullRom.cpp @@ -63,7 +63,7 @@ PointArray* PointArray::create(ssize_t capacity) bool PointArray::initWithCapacity(ssize_t capacity) { - _controlPoints = new vector(); + _controlPoints = new (std::nothrow) vector(); return true; } @@ -158,7 +158,7 @@ ssize_t PointArray::count() const PointArray* PointArray::reverse() const { - vector *newArray = new vector(); + vector *newArray = new (std::nothrow) vector(); vector::reverse_iterator iter; Vec2 *point = nullptr; for (iter = _controlPoints->rbegin(); iter != _controlPoints->rend(); ++iter) diff --git a/cocos/2d/CCActionInstant.cpp b/cocos/2d/CCActionInstant.cpp index b81b7055ab..0a3e4fb30c 100644 --- a/cocos/2d/CCActionInstant.cpp +++ b/cocos/2d/CCActionInstant.cpp @@ -494,7 +494,7 @@ CallFuncN * CallFuncN::clone() const __CCCallFuncND * __CCCallFuncND::create(Ref* selectorTarget, SEL_CallFuncND selector, void* d) { - __CCCallFuncND* ret = new __CCCallFuncND(); + __CCCallFuncND* ret = new (std::nothrow) __CCCallFuncND(); if (ret && ret->initWithTarget(selectorTarget, selector, d)) { ret->autorelease(); @@ -528,7 +528,7 @@ void __CCCallFuncND::execute() __CCCallFuncND * __CCCallFuncND::clone() const { // no copy constructor - auto a = new __CCCallFuncND(); + auto a = new (std::nothrow) __CCCallFuncND(); if( _selectorTarget) { @@ -561,7 +561,7 @@ void __CCCallFuncO::execute() __CCCallFuncO * __CCCallFuncO::create(Ref* selectorTarget, SEL_CallFuncO selector, Ref* object) { - __CCCallFuncO *ret = new __CCCallFuncO(); + __CCCallFuncO *ret = new (std::nothrow) __CCCallFuncO(); if (ret && ret->initWithTarget(selectorTarget, selector, object)) { ret->autorelease(); @@ -589,7 +589,7 @@ bool __CCCallFuncO::initWithTarget(Ref* selectorTarget, SEL_CallFuncO selector, __CCCallFuncO * __CCCallFuncO::clone() const { // no copy constructor - auto a = new __CCCallFuncO(); + auto a = new (std::nothrow) __CCCallFuncO(); if( _selectorTarget) { diff --git a/cocos/2d/CCAutoPolygon.cpp b/cocos/2d/CCAutoPolygon.cpp index 2781894b9a..eec77cec05 100644 --- a/cocos/2d/CCAutoPolygon.cpp +++ b/cocos/2d/CCAutoPolygon.cpp @@ -46,8 +46,8 @@ rect() filename = other.filename; isVertsOwner = true; rect = other.rect; - triangles.verts = new V3F_C4B_T2F[other.triangles.vertCount]; - triangles.indices = new unsigned short[other.triangles.indexCount]; + triangles.verts = new (std::nothrow) V3F_C4B_T2F[other.triangles.vertCount]; + triangles.indices = new (std::nothrow) unsigned short[other.triangles.indexCount]; triangles.vertCount = other.triangles.vertCount; triangles.indexCount = other.triangles.indexCount; memcpy(triangles.verts, other.triangles.verts, other.triangles.vertCount*sizeof(V3F_C4B_T2F)); @@ -62,8 +62,8 @@ PolygonInfo& PolygonInfo::operator= (const PolygonInfo& other) filename = other.filename; isVertsOwner = true; rect = other.rect; - triangles.verts = new V3F_C4B_T2F[other.triangles.vertCount]; - triangles.indices = new unsigned short[other.triangles.indexCount]; + triangles.verts = new (std::nothrow) V3F_C4B_T2F[other.triangles.vertCount]; + triangles.indices = new (std::nothrow) unsigned short[other.triangles.indexCount]; triangles.vertCount = other.triangles.vertCount; triangles.indexCount = other.triangles.indexCount; memcpy(triangles.verts, other.triangles.verts, other.triangles.vertCount*sizeof(V3F_C4B_T2F)); @@ -148,7 +148,7 @@ AutoPolygon::AutoPolygon(const std::string &filename) ,_scaleFactor(0) { _filename = filename; - _image = new Image(); + _image = new (std::nothrow) Image(); _image->initWithImageFile(filename); CCASSERT(_image->getRenderFormat()==Texture2D::PixelFormat::RGBA8888, "unsupported format, currently only supports rgba8888"); _data = _image->getData(); @@ -550,15 +550,15 @@ TrianglesCommand::Triangles AutoPolygon::triangulate(const std::vector& po std::vector p2points; for(std::vector::const_iterator it = points.begin(); itx, it->y); + p2t::Point * p = new (std::nothrow) p2t::Point(it->x, it->y); p2points.push_back(p); } p2t::CDT cdt(p2points); cdt.Triangulate(); std::vector tris = cdt.GetTriangles(); - V3F_C4B_T2F* verts= new V3F_C4B_T2F[points.size()]; - unsigned short* indices = new unsigned short[tris.size()*3]; + V3F_C4B_T2F* verts= new (std::nothrow) V3F_C4B_T2F[points.size()]; + unsigned short* indices = new (std::nothrow) unsigned short[tris.size()*3]; unsigned short idx = 0; unsigned short vdx = 0; diff --git a/cocos/2d/CCClippingRectangleNode.cpp b/cocos/2d/CCClippingRectangleNode.cpp index eb3476858b..ce42e7ae52 100644 --- a/cocos/2d/CCClippingRectangleNode.cpp +++ b/cocos/2d/CCClippingRectangleNode.cpp @@ -9,7 +9,7 @@ NS_CC_BEGIN ClippingRectangleNode* ClippingRectangleNode::create(const Rect& clippingRegion) { - ClippingRectangleNode* node = new ClippingRectangleNode(); + ClippingRectangleNode* node = new (std::nothrow) ClippingRectangleNode(); if (node && node->init()) { node->setClippingRegion(clippingRegion); node->autorelease(); @@ -22,7 +22,7 @@ ClippingRectangleNode* ClippingRectangleNode::create(const Rect& clippingRegion) ClippingRectangleNode* ClippingRectangleNode::create() { - ClippingRectangleNode* node = new ClippingRectangleNode(); + ClippingRectangleNode* node = new (std::nothrow) ClippingRectangleNode(); if (node && node->init()) { node->autorelease(); } else { diff --git a/cocos/2d/CCFastTMXLayer.cpp b/cocos/2d/CCFastTMXLayer.cpp index dd30153c75..34e4f046cc 100644 --- a/cocos/2d/CCFastTMXLayer.cpp +++ b/cocos/2d/CCFastTMXLayer.cpp @@ -177,7 +177,8 @@ void TMXLayer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags) if(iter.second->getCount() > 0) { auto& cmd = _renderCommands[index++]; - cmd.init(iter.first, _texture->getName(), getGLProgramState(), BlendFunc::ALPHA_NON_PREMULTIPLIED, iter.second, _modelViewTransform, flags); + auto blendfunc = _texture->hasPremultipliedAlpha() ? BlendFunc::ALPHA_PREMULTIPLIED : BlendFunc::ALPHA_NON_PREMULTIPLIED; + cmd.init(iter.first, _texture->getName(), getGLProgramState(), blendfunc, iter.second, _modelViewTransform, flags); renderer->addCommand(&cmd); } } diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 37c360294d..68e36b933d 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -79,7 +79,7 @@ FontAtlas::FontAtlas(Font &theFont) _currentPageDataSize *= 2; } - _currentPageData = new unsigned char[_currentPageDataSize]; + _currentPageData = new (std::nothrow) unsigned char[_currentPageDataSize]; memset(_currentPageData, 0, _currentPageDataSize); auto pixelFormat = outlineSize > 0 ? Texture2D::PixelFormat::AI88 : Texture2D::PixelFormat::A8; @@ -110,7 +110,7 @@ FontAtlas::~FontAtlas() #endif _font->release(); - relaseTextures(); + releaseTextures(); delete []_currentPageData; @@ -123,7 +123,7 @@ FontAtlas::~FontAtlas() #endif } -void FontAtlas::relaseTextures() +void FontAtlas::releaseTextures() { for( auto &item: _atlasTextures) { @@ -132,6 +132,11 @@ void FontAtlas::relaseTextures() _atlasTextures.clear(); } +void FontAtlas::relaseTextures() +{ + releaseTextures(); +} + void FontAtlas::purgeTexturesAtlas() { if (_fontFreeType && _atlasTextures.size() > 1) diff --git a/cocos/2d/CCFontAtlas.h b/cocos/2d/CCFontAtlas.h index 433c47b705..df9da05238 100644 --- a/cocos/2d/CCFontAtlas.h +++ b/cocos/2d/CCFontAtlas.h @@ -109,7 +109,10 @@ public: void setAliasTexParameters(); protected: - void relaseTextures(); + void releaseTextures(); + + /** @deprecated Use method releaseTextures() instead */ + CC_DEPRECATED_ATTRIBUTE void relaseTextures(); void findNewCharacters(const std::u16string& u16Text, std::unordered_map& charCodeMap); diff --git a/cocos/2d/CCFontFNT.cpp b/cocos/2d/CCFontFNT.cpp index 1d95388eee..3914a0ff70 100644 --- a/cocos/2d/CCFontFNT.cpp +++ b/cocos/2d/CCFontFNT.cpp @@ -290,7 +290,7 @@ std::set* BMFontConfiguration::parseConfigFile(const std::string& return nullptr; } - std::set *validCharsString = new std::set(); + std::set *validCharsString = new (std::nothrow) std::set(); auto contentsLen = data.getSize(); char line[512]; @@ -364,7 +364,7 @@ std::set* BMFontConfiguration::parseBinaryConfigFile(unsigned char { /* based on http://www.angelcode.com/products/bmfont/doc/file_format.html file format */ - set *validCharsString = new set(); + set *validCharsString = new (std::nothrow) set(); unsigned long remains = size; @@ -687,7 +687,7 @@ int * FontFNT::getHorizontalKerningForTextUTF16(const std::u16string& text, int if (!outNumLetters) return 0; - int *sizes = new int[outNumLetters]; + int *sizes = new (std::nothrow) int[outNumLetters]; if (!sizes) return 0; @@ -821,7 +821,7 @@ void FontFNT::reloadBMFontResource(const std::string& fntFilePath) if (ret) { s_configurations->insert(fntFilePath, ret); - TextureCache::getInstance()->reloadTexture(ret->getAtlasName()); + Director::getInstance()->getTextureCache()->reloadTexture(ret->getAtlasName()); } } diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index 0bc9234b4f..e8e0bb2daa 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -230,7 +230,7 @@ int * FontFreeType::getHorizontalKerningForTextUTF16(const std::u16string& text, if (!outNumLetters) return nullptr; - int *sizes = new int[outNumLetters]; + int *sizes = new (std::nothrow) int[outNumLetters]; if (!sizes) return nullptr; memset(sizes,0,outNumLetters * sizeof(int)); @@ -309,7 +309,7 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid if (_outlineSize > 0) { - auto copyBitmap = new unsigned char[outWidth * outHeight]; + auto copyBitmap = new (std::nothrow) unsigned char[outWidth * outHeight]; memcpy(copyBitmap,ret,outWidth * outHeight * sizeof(unsigned char)); FT_BBox bbox; @@ -342,7 +342,7 @@ unsigned char* FontFreeType::getGlyphBitmap(unsigned short theChar, long &outWid outRect.origin.y = -blendImageMaxY + _outlineSize; long index, index2; - auto blendImage = new unsigned char[blendWidth * blendHeight * 2]; + auto blendImage = new (std::nothrow) unsigned char[blendWidth * blendHeight * 2]; memset(blendImage, 0, blendWidth * blendHeight * 2); auto px = outlineMinX - blendImageMinX; @@ -415,7 +415,7 @@ unsigned char * FontFreeType::getGlyphBitmapWithOutline(unsigned short theChar, long rows = (bbox.yMax - bbox.yMin)>>6; FT_Bitmap bmp; - bmp.buffer = new unsigned char[width * rows]; + bmp.buffer = new (std::nothrow) unsigned char[width * rows]; memset(bmp.buffer, 0, width * rows); bmp.width = (int)width; bmp.rows = (int)rows; diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 53d290441a..e69ca8bef4 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -52,6 +52,7 @@ public: LabelLetter() { _textureAtlas = nullptr; + _letterVisible = true; } static LabelLetter* createWithTexture(Texture2D *texture, const Rect& rect, bool rotated = false) @@ -59,7 +60,7 @@ public: auto letter = new (std::nothrow) LabelLetter(); if (letter && letter->initWithTexture(texture, rect, rotated)) { - letter->setVisible(false); + letter->Sprite::setVisible(false); letter->autorelease(); return letter; } @@ -130,13 +131,18 @@ public: return; } - Color4B color4(_displayedColor.r, _displayedColor.g, _displayedColor.b, _displayedOpacity); + auto displayedOpacity = _displayedOpacity; + if(!_letterVisible) + { + displayedOpacity = 0.0f; + } + Color4B color4(_displayedColor.r, _displayedColor.g, _displayedColor.b, displayedOpacity); // special opacity for premultiplied textures if (_opacityModifyRGB) { - color4.r *= _displayedOpacity / 255.0f; - color4.g *= _displayedOpacity / 255.0f; - color4.b *= _displayedOpacity / 255.0f; + color4.r *= displayedOpacity / 255.0f; + color4.g *= displayedOpacity / 255.0f; + color4.b *= displayedOpacity / 255.0f; } _quad.bl.colors = color4; _quad.br.colors = color4; @@ -146,10 +152,19 @@ public: _textureAtlas->updateQuad(&_quad, _atlasIndex); } + void setVisible(bool visible) override + { + _letterVisible = visible; + updateColor(); + } + //LabelLetter doesn't need to draw directly. void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override { } + +private: + bool _letterVisible; }; Label* Label::create() diff --git a/cocos/2d/CCProgressTimer.cpp b/cocos/2d/CCProgressTimer.cpp index cb6a0787f3..c31a4b706c 100644 --- a/cocos/2d/CCProgressTimer.cpp +++ b/cocos/2d/CCProgressTimer.cpp @@ -54,17 +54,14 @@ ProgressTimer::ProgressTimer() ProgressTimer* ProgressTimer::create(Sprite* sp) { ProgressTimer *progressTimer = new (std::nothrow) ProgressTimer(); - if (progressTimer->initWithSprite(sp)) + if (progressTimer && progressTimer->initWithSprite(sp)) { progressTimer->autorelease(); + return progressTimer; } - else - { - delete progressTimer; - progressTimer = nullptr; - } - - return progressTimer; + + delete progressTimer; + return nullptr; } bool ProgressTimer::initWithSprite(Sprite* sp) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index e401be8d6b..8851f9996a 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -142,9 +142,11 @@ Sprite* Sprite::create() return nullptr; } -bool Sprite::init(void) +bool Sprite::init() { - return initWithTexture(nullptr, Rect::ZERO ); + initWithTexture(nullptr, Rect::ZERO); + + return true; } bool Sprite::initWithTexture(Texture2D *texture) @@ -152,9 +154,11 @@ bool Sprite::initWithTexture(Texture2D *texture) CCASSERT(texture != nullptr, "Invalid texture for sprite"); Rect rect = Rect::ZERO; - rect.size = texture->getContentSize(); + if (texture) { + rect.size = texture->getContentSize(); + } - return initWithTexture(texture, rect); + return initWithTexture(texture, rect, false); } bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect) @@ -173,7 +177,7 @@ bool Sprite::initWithFile(const std::string& filename) _fileName = filename; _fileType = 0; - Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { Rect rect = Rect::ZERO; @@ -189,12 +193,16 @@ bool Sprite::initWithFile(const std::string& filename) bool Sprite::initWithFile(const std::string &filename, const Rect& rect) { - CCASSERT(filename.size()>0, "Invalid filename"); - + CCASSERT(!filename.empty(), "Invalid filename"); + if (filename.empty()) + { + return false; + } + _fileName = filename; _fileType = 0; - Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(filename); + Texture2D *texture = _director->getTextureCache()->addImage(filename); if (texture) { return initWithTexture(texture, rect); @@ -208,8 +216,12 @@ bool Sprite::initWithFile(const std::string &filename, const Rect& rect) bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) { - CCASSERT(spriteFrameName.size() > 0, "Invalid spriteFrameName"); - + CCASSERT(!spriteFrameName.empty(), "Invalid spriteFrameName"); + if (spriteFrameName.empty()) + { + return false; + } + _fileName = spriteFrameName; _fileType = 1; @@ -220,7 +232,11 @@ bool Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) { CCASSERT(spriteFrame != nullptr, "spriteFrame can't be nullptr!"); - + if (spriteFrame == nullptr) + { + return false; + } + bool bRet = initWithTexture(spriteFrame->getTexture(), spriteFrame->getRect()); setSpriteFrame(spriteFrame); @@ -229,21 +245,23 @@ bool Sprite::initWithSpriteFrame(SpriteFrame *spriteFrame) bool Sprite::initWithPolygon(const cocos2d::PolygonInfo &info) { - Texture2D *texture = Director::getInstance()->getTextureCache()->addImage(info.filename); - bool res = false; - if(initWithTexture(texture)) + bool ret = false; + + Texture2D *texture = _director->getTextureCache()->addImage(info.filename); + if(texture && initWithTexture(texture)) { _polyInfo = info; - setContentSize(_polyInfo.rect.size/Director::getInstance()->getContentScaleFactor()); - res = true; + setContentSize(_polyInfo.rect.size / _director->getContentScaleFactor()); + ret = true; } - return res; + + return ret; } // designated initializer bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) { - bool result; + bool result = false; if (Node::init()) { _batchNode = nullptr; @@ -284,12 +302,10 @@ bool Sprite::initWithTexture(Texture2D *texture, const Rect& rect, bool rotated) setBatchNode(nullptr); result = true; } - else - { - result = false; - } + _recursiveDirty = true; setDirty(true); + return result; } @@ -359,7 +375,7 @@ void Sprite::setTexture(Texture2D *texture) if (texture == nullptr) { // Gets the texture by key firstly. - texture = Director::getInstance()->getTextureCache()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY); + texture = _director->getTextureCache()->getTextureForKey(CC_2x2_WHITE_IMAGE_KEY); // If texture wasn't in cache, create it from RAW data. if (texture == nullptr) @@ -369,7 +385,7 @@ void Sprite::setTexture(Texture2D *texture) CC_UNUSED_PARAM(isOK); CCASSERT(isOK, "The 2x2 empty texture was created unsuccessfully."); - texture = Director::getInstance()->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); + texture = _director->getTextureCache()->addImage(image, CC_2x2_WHITE_IMAGE_KEY); CC_SAFE_RELEASE(image); } } @@ -451,13 +467,13 @@ void Sprite::setVertexRect(const Rect& rect) void Sprite::setTextureCoords(Rect rect) { - rect = CC_RECT_POINTS_TO_PIXELS(rect); - Texture2D *tex = _batchNode ? _textureAtlas->getTexture() : _texture; - if (! tex) + if (tex == nullptr) { return; } + + rect = CC_RECT_POINTS_TO_PIXELS(rect); float atlasWidth = (float)tex->getPixelsWide(); float atlasHeight = (float)tex->getPixelsHigh(); @@ -637,6 +653,11 @@ void Sprite::updateTransform(void) void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { + if (_texture == nullptr) + { + return; + } + #if CC_USE_CULLING // Don't do calculate the culling if the transform was not updated auto visitingCamera = Camera::getVisitingCamera(); @@ -684,7 +705,11 @@ void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) void Sprite::addChild(Node *child, int zOrder, int tag) { CCASSERT(child != nullptr, "Argument must be non-nullptr"); - + if (child == nullptr) + { + return; + } + if (_batchNode) { Sprite* childSprite = dynamic_cast(child); @@ -705,6 +730,10 @@ void Sprite::addChild(Node *child, int zOrder, int tag) void Sprite::addChild(Node *child, int zOrder, const std::string &name) { CCASSERT(child != nullptr, "Argument must be non-nullptr"); + if (child == nullptr) + { + return; + } if (_batchNode) { @@ -1012,6 +1041,12 @@ bool Sprite::isOpacityModifyRGB(void) const void Sprite::setSpriteFrame(const std::string &spriteFrameName) { + CCASSERT(!spriteFrameName.empty(), "spriteFrameName must not be empty"); + if (spriteFrameName.empty()) + { + return; + } + SpriteFrameCache *cache = SpriteFrameCache::getInstance(); SpriteFrame *spriteFrame = cache->getSpriteFrameByName(spriteFrameName); @@ -1051,8 +1086,12 @@ void Sprite::setSpriteFrame(SpriteFrame *spriteFrame) void Sprite::setDisplayFrameWithAnimationName(const std::string& animationName, ssize_t frameIndex) { - CCASSERT(animationName.size()>0, "CCSprite#setDisplayFrameWithAnimationName. animationName must not be nullptr"); - + CCASSERT(!animationName.empty(), "CCSprite#setDisplayFrameWithAnimationName. animationName must not be nullptr"); + if (animationName.empty()) + { + return; + } + Animation *a = AnimationCache::getInstance()->getAnimation(animationName); CCASSERT(a, "CCSprite#setDisplayFrameWithAnimationName: Frame not found"); diff --git a/cocos/2d/CCSpriteBatchNode.cpp b/cocos/2d/CCSpriteBatchNode.cpp index 96a78e6d83..c2b5f0e71d 100644 --- a/cocos/2d/CCSpriteBatchNode.cpp +++ b/cocos/2d/CCSpriteBatchNode.cpp @@ -45,10 +45,14 @@ NS_CC_BEGIN SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capacity/* = DEFAULT_CAPACITY*/) { SpriteBatchNode *batchNode = new (std::nothrow) SpriteBatchNode(); - batchNode->initWithTexture(tex, capacity); - batchNode->autorelease(); - - return batchNode; + if(batchNode && batchNode->initWithTexture(tex, capacity)) + { + batchNode->autorelease(); + return batchNode; + } + + delete batchNode; + return nullptr; } /* @@ -58,10 +62,14 @@ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capa SpriteBatchNode* SpriteBatchNode::create(const std::string& fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/) { SpriteBatchNode *batchNode = new (std::nothrow) SpriteBatchNode(); - batchNode->initWithFile(fileImage, capacity); - batchNode->autorelease(); - - return batchNode; + if(batchNode && batchNode->initWithFile(fileImage, capacity)) + { + batchNode->autorelease(); + return batchNode; + } + + delete batchNode; + return nullptr; } /* @@ -69,6 +77,11 @@ SpriteBatchNode* SpriteBatchNode::create(const std::string& fileImage, ssize_t c */ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity/* = DEFAULT_CAPACITY*/) { + if(tex == nullptr) + { + return false; + } + CCASSERT(capacity>=0, "Capacity must be >= 0"); _blendFunc = BlendFunc::ALPHA_PREMULTIPLIED; @@ -78,7 +91,7 @@ bool SpriteBatchNode::initWithTexture(Texture2D *tex, ssize_t capacity/* = DEFAU } _textureAtlas = new (std::nothrow) TextureAtlas(); - if (capacity == 0) + if (capacity <= 0) { capacity = DEFAULT_CAPACITY; } @@ -148,13 +161,12 @@ void SpriteBatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uin // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it - Director* director = Director::getInstance(); - director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); - director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); + _director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); draw(renderer, _modelViewTransform, flags); - director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); + _director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); diff --git a/cocos/2d/CCSpriteFrameCache.cpp b/cocos/2d/CCSpriteFrameCache.cpp index dde20244e6..9e93e2595f 100644 --- a/cocos/2d/CCSpriteFrameCache.cpp +++ b/cocos/2d/CCSpriteFrameCache.cpp @@ -113,7 +113,7 @@ void SpriteFrameCache::initializePolygonInfo(const Size &textureSize, float scaleFactor = CC_CONTENT_SCALE_FACTOR(); - V3F_C4B_T2F *vertexData = new V3F_C4B_T2F[vertexCount]; + V3F_C4B_T2F *vertexData = new (std::nothrow) V3F_C4B_T2F[vertexCount]; for (size_t i = 0; i < vertexCount/2; i++) { vertexData[i].colors = Color4B::WHITE; @@ -282,7 +282,7 @@ void SpriteFrameCache::addSpriteFramesWithDictionary(ValueMap& dictionary, Textu if(flag) { if (image == nullptr) { - image = new Image(); + image = new (std::nothrow) Image(); image->initWithImageFile(textureFileName); } parser.setSpriteFrameInfo(image, spriteFrame->getRectInPixels(), spriteFrame->isRotated()); diff --git a/cocos/3d/CCBundle3D.cpp b/cocos/3d/CCBundle3D.cpp index 5d00c10f33..762f548a5e 100644 --- a/cocos/3d/CCBundle3D.cpp +++ b/cocos/3d/CCBundle3D.cpp @@ -1131,7 +1131,7 @@ bool Bundle3D::loadBinary(const std::string& path) bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas) { const rapidjson::Value& mesh_data_array = _jsonReader[MESH]; - MeshData* meshdata= new MeshData(); + MeshData* meshdata= new (std::nothrow) MeshData(); const rapidjson::Value& mesh_data_val = mesh_data_array[(rapidjson::SizeType)0]; const rapidjson::Value& mesh_data_body_array = mesh_data_val[DEFAULTPART]; @@ -1179,7 +1179,7 @@ bool Bundle3D::loadMeshDataJson_0_1(MeshDatas& meshdatas) bool Bundle3D::loadMeshDataJson_0_2(MeshDatas& meshdatas) { - MeshData* meshdata= new MeshData(); + MeshData* meshdata= new (std::nothrow) MeshData(); const rapidjson::Value& mesh_array = _jsonReader[MESH]; const rapidjson::Value& mesh_array_0 = mesh_array[(rapidjson::SizeType)0]; diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index 4a3ec6ca69..1e490a704e 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -364,6 +364,13 @@ Sprite3D* Sprite3D::createSprite3DNode(NodeData* nodedata,ModelData* modeldata,c { sprite->setName(nodedata->id); auto mesh = Mesh::create(nodedata->id, getMeshIndexData(modeldata->subMeshId)); + + if (_skeleton && modeldata->bones.size()) + { + auto skin = MeshSkin::create(_skeleton, modeldata->bones, modeldata->invBindPose); + mesh->setSkin(skin); + } + if (modeldata->matrialId == "" && materialdatas.materials.size()) { const NTextureData* textureData = materialdatas.materials[0].getTextureData(NTextureData::Usage::Diffuse); @@ -748,7 +755,7 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { #if CC_USE_CULLING // camera clipping - if(Camera::getVisitingCamera() && !Camera::getVisitingCamera()->isVisibleInFrustum(&this->getAABB())) + if(_children.size() == 0 && Camera::getVisitingCamera() && !Camera::getVisitingCamera()->isVisibleInFrustum(&getAABB())) return; #endif diff --git a/cocos/3d/CCTerrain.cpp b/cocos/3d/CCTerrain.cpp index 79b4731a5e..1686f3b7c2 100644 --- a/cocos/3d/CCTerrain.cpp +++ b/cocos/3d/CCTerrain.cpp @@ -225,7 +225,7 @@ void Terrain::onDraw(const Mat4 &transform, uint32_t flags) bool Terrain::initHeightMap(const std::string& heightMap) { - _heightMapImage = new Image(); + _heightMapImage = new (std::nothrow) Image(); _heightMapImage->initWithImageFile(heightMap); _data = _heightMapImage->getData(); _imageWidth =_heightMapImage->getWidth(); @@ -244,7 +244,7 @@ bool Terrain::initHeightMap(const std::string& heightMap) { for(int n =0; n_terrain = this; _chunkesArray[m][n]->_size = _chunkSize; _chunkesArray[m][n]->generate(_imageWidth,_imageHeight,m,n,_data); @@ -262,7 +262,7 @@ bool Terrain::initHeightMap(const std::string& heightMap) if(m+1_front = _chunkesArray[m+1][n]; } } - _quadRoot = new QuadTree(0,0,_imageWidth,_imageHeight,this); + _quadRoot = new (std::nothrow) QuadTree(0,0,_imageWidth,_imageHeight,this); setLODDistance(_chunkSize.width,2*_chunkSize.width,3*_chunkSize.width); return true; }else @@ -1487,13 +1487,13 @@ Terrain::QuadTree::QuadTree(int x, int y, int w, int h, Terrain * terrain) if(_width> terrain->_chunkSize.width &&_height >terrain->_chunkSize.height) //subdivision { _isTerminal = false; - this->_tl = new QuadTree(x,y,_width/2,_height/2,terrain); + this->_tl = new (std::nothrow) QuadTree(x,y,_width/2,_height/2,terrain); this->_tl->_parent = this; - this->_tr = new QuadTree(x+_width/2,y,_width/2,_height/2,terrain); + this->_tr = new (std::nothrow) QuadTree(x+_width/2,y,_width/2,_height/2,terrain); this->_tr->_parent = this; - this->_bl = new QuadTree(x,y+_height/2,_width/2,_height/2,terrain); + this->_bl = new (std::nothrow) QuadTree(x,y+_height/2,_width/2,_height/2,terrain); this->_bl->_parent = this; - this->_br = new QuadTree(x+_width/2,y+_height/2,_width/2,_height/2,terrain); + this->_br = new (std::nothrow) QuadTree(x+_width/2,y+_height/2,_width/2,_height/2,terrain); this->_br->_parent = this; _localAABB.merge(_tl->_localAABB); diff --git a/cocos/base/CCConfiguration.cpp b/cocos/base/CCConfiguration.cpp index 654100433b..01c20740c9 100644 --- a/cocos/base/CCConfiguration.cpp +++ b/cocos/base/CCConfiguration.cpp @@ -57,7 +57,7 @@ Configuration::Configuration() , _maxSpotLightInShader(1) , _animate3DQuality(Animate3DQuality::QUALITY_LOW) { - _loadedEvent = new EventCustom(CONFIG_FILE_LOADED); + _loadedEvent = new (std::nothrow) EventCustom(CONFIG_FILE_LOADED); } bool Configuration::init() diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 1494486bf1..43e5aef68b 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -126,7 +126,7 @@ bool Director::init(void) _frameRate = 0.0f; _FPSLabel = _drawnBatchesLabel = _drawnVerticesLabel = nullptr; _totalFrames = 0; - _lastUpdate = new struct timeval; + _lastUpdate = new (std::nothrow) struct timeval; _secondsPerFrame = 1.0f; // paused ? diff --git a/cocos/base/CCEventDispatcher.cpp b/cocos/base/CCEventDispatcher.cpp index fc39de9fbf..efb625e111 100644 --- a/cocos/base/CCEventDispatcher.cpp +++ b/cocos/base/CCEventDispatcher.cpp @@ -153,7 +153,7 @@ void EventDispatcher::EventListenerVector::push_back(EventListener* listener) { if (_sceneGraphListeners == nullptr) { - _sceneGraphListeners = new std::vector(); + _sceneGraphListeners = new (std::nothrow) std::vector(); _sceneGraphListeners->reserve(100); } @@ -412,7 +412,7 @@ void EventDispatcher::associateNodeAndEventListener(Node* node, EventListener* l } else { - listeners = new std::vector(); + listeners = new (std::nothrow) std::vector(); _nodeListenersMap.insert(std::make_pair(node, listeners)); } diff --git a/cocos/base/CCScheduler.cpp b/cocos/base/CCScheduler.cpp index 90f4a3d60b..a4a0d00f58 100644 --- a/cocos/base/CCScheduler.cpp +++ b/cocos/base/CCScheduler.cpp @@ -383,7 +383,7 @@ void Scheduler::unschedule(const std::string &key, void *target) void Scheduler::priorityIn(tListEntry **list, const ccSchedulerFunc& callback, void *target, int priority, bool paused) { - tListEntry *listElement = new tListEntry(); + tListEntry *listElement = new (std::nothrow) tListEntry(); listElement->callback = callback; listElement->target = target; @@ -440,7 +440,7 @@ void Scheduler::priorityIn(tListEntry **list, const ccSchedulerFunc& callback, v void Scheduler::appendIn(_listEntry **list, const ccSchedulerFunc& callback, void *target, bool paused) { - tListEntry *listElement = new tListEntry(); + tListEntry *listElement = new (std::nothrow) tListEntry(); listElement->callback = callback; listElement->target = target; diff --git a/cocos/base/CCUserDefault-android.cpp b/cocos/base/CCUserDefault-android.cpp index 162ae29729..ca9ad19de3 100644 --- a/cocos/base/CCUserDefault-android.cpp +++ b/cocos/base/CCUserDefault-android.cpp @@ -74,7 +74,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc do { - tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); + tinyxml2::XMLDocument* xmlDoc = new (std::nothrow) tinyxml2::XMLDocument(); *doc = xmlDoc; ssize_t size; diff --git a/cocos/base/CCUserDefault-apple.mm b/cocos/base/CCUserDefault-apple.mm index 9476cbb420..ea128626a4 100644 --- a/cocos/base/CCUserDefault-apple.mm +++ b/cocos/base/CCUserDefault-apple.mm @@ -75,7 +75,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLDoc do { - tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); + tinyxml2::XMLDocument* xmlDoc = new (std::nothrow) tinyxml2::XMLDocument(); *doc = xmlDoc; std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath()); diff --git a/cocos/base/CCUserDefault.cpp b/cocos/base/CCUserDefault.cpp index 880ef4d2a8..ebc674877c 100644 --- a/cocos/base/CCUserDefault.cpp +++ b/cocos/base/CCUserDefault.cpp @@ -57,7 +57,7 @@ static tinyxml2::XMLElement* getXMLNodeForKey(const char* pKey, tinyxml2::XMLEle do { - tinyxml2::XMLDocument* xmlDoc = new tinyxml2::XMLDocument(); + tinyxml2::XMLDocument* xmlDoc = new (std::nothrow) tinyxml2::XMLDocument(); *doc = xmlDoc; std::string xmlBuffer = FileUtils::getInstance()->getStringFromFile(UserDefault::getInstance()->getXMLFilePath()); @@ -467,7 +467,7 @@ void UserDefault::initXMLFilePath() bool UserDefault::createXMLFile() { bool bRet = false; - tinyxml2::XMLDocument *pDoc = new tinyxml2::XMLDocument(); + tinyxml2::XMLDocument *pDoc = new (std::nothrow) tinyxml2::XMLDocument(); if (nullptr==pDoc) { return false; diff --git a/cocos/base/CCValue.cpp b/cocos/base/CCValue.cpp index 4e28db6fc0..9a838d1dae 100644 --- a/cocos/base/CCValue.cpp +++ b/cocos/base/CCValue.cpp @@ -74,7 +74,7 @@ Value::Value(bool v) Value::Value(const char* v) : _type(Type::STRING) { - _field.strVal = new std::string(); + _field.strVal = new (std::nothrow) std::string(); if (v) { *_field.strVal = v; @@ -84,7 +84,7 @@ Value::Value(const char* v) Value::Value(const std::string& v) : _type(Type::STRING) { - _field.strVal = new std::string(); + _field.strVal = new (std::nothrow) std::string(); *_field.strVal = v; } @@ -813,7 +813,7 @@ void Value::reset(Type type) switch (type) { case Type::STRING: - _field.strVal = new std::string(); + _field.strVal = new (std::nothrow) std::string(); break; case Type::VECTOR: _field.vectorVal = new (std::nothrow) ValueVector(); diff --git a/cocos/base/ZipUtils.cpp b/cocos/base/ZipUtils.cpp index 30ac76fd94..6051dd6fba 100644 --- a/cocos/base/ZipUtils.cpp +++ b/cocos/base/ZipUtils.cpp @@ -518,7 +518,7 @@ public: ZipFile *ZipFile::createWithBuffer(const void* buffer, uLong size) { - ZipFile *zip = new ZipFile(); + ZipFile *zip = new (std::nothrow) ZipFile(); if (zip && zip->initWithBuffer(buffer, size)) { return zip; } else { diff --git a/cocos/base/ccUTF8.cpp b/cocos/base/ccUTF8.cpp index 45f47d4c68..f46f86f0ae 100644 --- a/cocos/base/ccUTF8.cpp +++ b/cocos/base/ccUTF8.cpp @@ -293,7 +293,7 @@ unsigned short* cc_utf8_to_utf16(const char* str_old, int length/* = -1*/, int* if (succeed) { - ret = new unsigned short[outUtf16.length() + 1]; + ret = new (std::nothrow) unsigned short[outUtf16.length() + 1]; ret[outUtf16.length()] = 0; memcpy(ret, outUtf16.data(), outUtf16.length() * sizeof(unsigned short)); if (rUtf16Size) @@ -328,7 +328,7 @@ char * cc_utf16_to_utf8 (const unsigned short *str, if (succeed) { - ret = new char[outUtf8.length() + 1]; + ret = new (std::nothrow) char[outUtf8.length() + 1]; ret[outUtf8.length()] = '\0'; memcpy(ret, outUtf8.data(), outUtf8.length()); } diff --git a/cocos/base/ccUtils.cpp b/cocos/base/ccUtils.cpp index 9a9e1304ae..83d35a5624 100644 --- a/cocos/base/ccUtils.cpp +++ b/cocos/base/ccUtils.cpp @@ -271,12 +271,12 @@ Sprite* createSpriteFromBase64(const char* base64String) unsigned char* decoded; int length = base64Decode((const unsigned char*) base64String, (unsigned int) strlen(base64String), &decoded); - Image *image = new Image(); + Image *image = new (std::nothrow) Image(); bool imageResult = image->initWithImageData(decoded, length); CCASSERT(imageResult, "Failed to create image from base64!"); free(decoded); - Texture2D *texture = new Texture2D(); + Texture2D *texture = new (std::nothrow) Texture2D(); texture->initWithImage(image); texture->setAliasTexParameters(); image->release(); diff --git a/cocos/deprecated/CCArray.cpp b/cocos/deprecated/CCArray.cpp index 80118faa74..c6174987ce 100644 --- a/cocos/deprecated/CCArray.cpp +++ b/cocos/deprecated/CCArray.cpp @@ -44,7 +44,7 @@ __Array::__Array() __Array* __Array::create() { - __Array* array = new __Array(); + __Array* array = new (std::nothrow) __Array(); if (array && array->initWithCapacity(7)) { @@ -60,7 +60,7 @@ __Array* __Array::create() __Array* __Array::createWithObject(Ref* object) { - __Array* array = new __Array(); + __Array* array = new (std::nothrow) __Array(); if (array && array->initWithObject(object)) { @@ -109,7 +109,7 @@ __Array* __Array::createWithCapacity(int capacity) { CCASSERT(capacity>=0, "Invalid capacity"); - __Array* array = new __Array(); + __Array* array = new (std::nothrow) __Array(); if (array && array->initWithCapacity(capacity)) { @@ -342,7 +342,7 @@ __Array::~Array() __Array* __Array::clone() const { - __Array* ret = new __Array(); + __Array* ret = new (std::nothrow) __Array(); ret->autorelease(); ret->initWithCapacity(this->data.size() > 0 ? this->data.size() : 1); @@ -387,7 +387,7 @@ __Array::__Array() __Array* __Array::create() { - __Array* array = new __Array(); + __Array* array = new (std::nothrow) __Array(); if (array && array->initWithCapacity(7)) { @@ -403,7 +403,7 @@ __Array* __Array::create() __Array* __Array::createWithObject(Ref* object) { - __Array* array = new __Array(); + __Array* array = new (std::nothrow) __Array(); if (array && array->initWithObject(object)) { @@ -452,7 +452,7 @@ __Array* __Array::createWithCapacity(ssize_t capacity) { CCASSERT(capacity>=0, "Invalid capacity"); - __Array* array = new __Array(); + __Array* array = new (std::nothrow) __Array(); if (array && array->initWithCapacity(capacity)) { @@ -728,7 +728,7 @@ __Array::~__Array() __Array* __Array::clone() const { - __Array* ret = new __Array(); + __Array* ret = new (std::nothrow) __Array(); ret->autorelease(); ret->initWithCapacity(this->data->num > 0 ? this->data->num : 1); diff --git a/cocos/deprecated/CCBool.h b/cocos/deprecated/CCBool.h index cfc76776d2..7a5a4690ca 100644 --- a/cocos/deprecated/CCBool.h +++ b/cocos/deprecated/CCBool.h @@ -46,7 +46,7 @@ public: static __Bool* create(bool v) { - __Bool* pRet = new __Bool(v); + __Bool* pRet = new (std::nothrow) __Bool(v); if (pRet) { pRet->autorelease(); diff --git a/cocos/deprecated/CCDictionary.cpp b/cocos/deprecated/CCDictionary.cpp index 5e24ccc73b..7141eb3a63 100644 --- a/cocos/deprecated/CCDictionary.cpp +++ b/cocos/deprecated/CCDictionary.cpp @@ -106,7 +106,7 @@ __Array* __Dictionary::allKeys() { HASH_ITER(hh, _elements, pElement, tmp) { - __String* pOneKey = new __String(pElement->_strKey); + __String* pOneKey = new (std::nothrow) __String(pElement->_strKey); array->addObject(pOneKey); CC_SAFE_RELEASE(pOneKey); } @@ -115,7 +115,7 @@ __Array* __Dictionary::allKeys() { HASH_ITER(hh, _elements, pElement, tmp) { - __Integer* pOneKey = new __Integer(static_cast(pElement->_intKey)); + __Integer* pOneKey = new (std::nothrow) __Integer(static_cast(pElement->_intKey)); array->addObject(pOneKey); CC_SAFE_RELEASE(pOneKey); } @@ -138,7 +138,7 @@ __Array* __Dictionary::allKeysForObject(Ref* object) { if (object == pElement->_object) { - __String* pOneKey = new __String(pElement->_strKey); + __String* pOneKey = new (std::nothrow) __String(pElement->_strKey); array->addObject(pOneKey); CC_SAFE_RELEASE(pOneKey); } @@ -150,7 +150,7 @@ __Array* __Dictionary::allKeysForObject(Ref* object) { if (object == pElement->_object) { - __Integer* pOneKey = new __Integer(static_cast(pElement->_intKey)); + __Integer* pOneKey = new (std::nothrow) __Integer(static_cast(pElement->_intKey)); array->addObject(pOneKey); CC_SAFE_RELEASE(pOneKey); } @@ -366,7 +366,7 @@ Ref* __Dictionary::randomObject() __Dictionary* __Dictionary::create() { - __Dictionary* ret = new __Dictionary(); + __Dictionary* ret = new (std::nothrow) __Dictionary(); if (ret && ret->init() ) { ret->autorelease(); @@ -388,7 +388,7 @@ static __Array* visitArray(const ValueVector& array); static __Dictionary* visitDict(const ValueMap& dict) { - __Dictionary* ret = new __Dictionary(); + __Dictionary* ret = new (std::nothrow) __Dictionary(); ret->init(); for (auto iter = dict.begin(); iter != dict.end(); ++iter) @@ -409,7 +409,7 @@ static __Dictionary* visitDict(const ValueMap& dict) } else { - auto str = new __String(iter->second.asString()); + auto str = new (std::nothrow) __String(iter->second.asString()); ret->setObject(str, iter->first); str->release(); } @@ -419,7 +419,7 @@ static __Dictionary* visitDict(const ValueMap& dict) static __Array* visitArray(const ValueVector& array) { - __Array* ret = new __Array(); + __Array* ret = new (std::nothrow) __Array(); ret->init(); for(const auto &value : array) { @@ -439,7 +439,7 @@ static __Array* visitArray(const ValueVector& array) } else { - auto str = new __String(value.asString()); + auto str = new (std::nothrow) __String(value.asString()); ret->addObject(str); str->release(); } diff --git a/cocos/deprecated/CCDouble.h b/cocos/deprecated/CCDouble.h index 5069f99551..13e120c9c5 100644 --- a/cocos/deprecated/CCDouble.h +++ b/cocos/deprecated/CCDouble.h @@ -45,7 +45,7 @@ public: static __Double* create(double v) { - __Double* pRet = new __Double(v); + __Double* pRet = new (std::nothrow) __Double(v); if (pRet) { pRet->autorelease(); diff --git a/cocos/deprecated/CCFloat.h b/cocos/deprecated/CCFloat.h index e4e78e8049..18e3cb46c1 100644 --- a/cocos/deprecated/CCFloat.h +++ b/cocos/deprecated/CCFloat.h @@ -45,7 +45,7 @@ public: static __Float* create(float v) { - __Float* pRet = new __Float(v); + __Float* pRet = new (std::nothrow) __Float(v); if (pRet) { pRet->autorelease(); diff --git a/cocos/deprecated/CCInteger.h b/cocos/deprecated/CCInteger.h index aeecce26bc..d5bb866453 100644 --- a/cocos/deprecated/CCInteger.h +++ b/cocos/deprecated/CCInteger.h @@ -43,7 +43,7 @@ class CC_DLL __Integer : public Ref, public Clonable public: static __Integer* create(int v) { - __Integer* pRet = new __Integer(v); + __Integer* pRet = new (std::nothrow) __Integer(v); pRet->autorelease(); return pRet; } diff --git a/cocos/deprecated/CCNotificationCenter.cpp b/cocos/deprecated/CCNotificationCenter.cpp index aea2f6bf14..11cf4131b9 100644 --- a/cocos/deprecated/CCNotificationCenter.cpp +++ b/cocos/deprecated/CCNotificationCenter.cpp @@ -53,7 +53,7 @@ __NotificationCenter *__NotificationCenter::getInstance() { if (!s_sharedNotifCenter) { - s_sharedNotifCenter = new __NotificationCenter; + s_sharedNotifCenter = new (std::nothrow) __NotificationCenter; } return s_sharedNotifCenter; } diff --git a/cocos/deprecated/CCSet.cpp b/cocos/deprecated/CCSet.cpp index 28c1d9bedb..1fe59c66ad 100644 --- a/cocos/deprecated/CCSet.cpp +++ b/cocos/deprecated/CCSet.cpp @@ -31,12 +31,12 @@ NS_CC_BEGIN __Set::__Set(void) { - _set = new set; + _set = new (std::nothrow) set; } __Set::__Set(const __Set &other) { - _set = new set(*other._set); + _set = new (std::nothrow) set(*other._set); // call retain of members __SetIterator iter; @@ -64,7 +64,7 @@ void __Set::acceptVisitor(DataVisitor &visitor) __Set * __Set::create() { - __Set * pRet = new __Set(); + __Set * pRet = new (std::nothrow) __Set(); if (pRet != nullptr) { @@ -76,7 +76,7 @@ __Set * __Set::create() __Set* __Set::copy(void) { - __Set *p__Set = new __Set(*this); + __Set *p__Set = new (std::nothrow) __Set(*this); return p__Set; } diff --git a/cocos/deprecated/CCString.cpp b/cocos/deprecated/CCString.cpp index a44867cdf8..ba548d77c0 100644 --- a/cocos/deprecated/CCString.cpp +++ b/cocos/deprecated/CCString.cpp @@ -220,7 +220,7 @@ bool __String::isEqual(const Ref* pObject) __String* __String::create(const std::string& str) { - __String* ret = new __String(str); + __String* ret = new (std::nothrow) __String(str); ret->autorelease(); return ret; } diff --git a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp index 4f763bed43..8ff41bf119 100644 --- a/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp +++ b/cocos/editor-support/cocosbuilder/CCNodeLoader.cpp @@ -468,7 +468,7 @@ float * NodeLoader::parsePropTypeFloatXY(Node * pNode, Node * pParent, CCBReader float x = ccbReader->readFloat(); float y = ccbReader->readFloat(); - float * floatXY = new float[2]; + float * floatXY = new (std::nothrow) float[2]; floatXY[0] = x; floatXY[1] = y; @@ -499,7 +499,7 @@ float * NodeLoader::parsePropTypeScaleLock(Node * pNode, Node * pParent, CCBRead y *= ccbReader->getResolutionScale(); } - float * scaleLock = new float[2]; + float * scaleLock = new (std::nothrow) float[2]; scaleLock[0] = x; scaleLock[1] = y; @@ -549,7 +549,7 @@ float * NodeLoader::parsePropTypeFloatVar(Node * pNode, Node * pParent, CCBReade float f = ccbReader->readFloat(); float fVar = ccbReader->readFloat(); - float * arr = new float[2]; + float * arr = new (std::nothrow) float[2]; arr[0] = f; arr[1] = fVar; @@ -705,7 +705,7 @@ bool * NodeLoader::parsePropTypeFlip(Node * pNode, Node * pParent, CCBReader * c bool flipX = ccbReader->readBool(); bool flipY = ccbReader->readBool(); - bool * arr = new bool[2]; + bool * arr = new (std::nothrow) bool[2]; arr[0] = flipX; arr[1] = flipY; diff --git a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp index f967fb4d68..53729aab38 100644 --- a/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp +++ b/cocos/editor-support/cocostudio/ActionTimeline/CSLoader.cpp @@ -171,7 +171,7 @@ CSLoader* CSLoader::getInstance() { if (! _sharedCSLoader) { - _sharedCSLoader = new CSLoader(); + _sharedCSLoader = new (std::nothrow) CSLoader(); _sharedCSLoader->init(); } @@ -742,7 +742,7 @@ Node* CSLoader::loadWidget(const rapidjson::Value& json) - WidgetPropertiesReader0300* widgetPropertiesReader = new WidgetPropertiesReader0300(); + WidgetPropertiesReader0300* widgetPropertiesReader = new (std::nothrow) WidgetPropertiesReader0300(); Widget* widget = nullptr; if (isWidget(classname)) diff --git a/cocos/editor-support/cocostudio/CCColliderDetector.cpp b/cocos/editor-support/cocostudio/CCColliderDetector.cpp index 597ab3b36f..3e10dd7abd 100644 --- a/cocos/editor-support/cocostudio/CCColliderDetector.cpp +++ b/cocos/editor-support/cocostudio/CCColliderDetector.cpp @@ -421,7 +421,7 @@ void ColliderDetector::setBody(b2Body *pBody) ContourData *contourData = colliderBody->getContourData(); - b2Vec2 *b2bv = new b2Vec2[contourData->vertexList.size()]; + b2Vec2 *b2bv = new (std::nothrow) b2Vec2[contourData->vertexList.size()]; int i = 0; for(auto& v : contourData->vertexList) @@ -470,7 +470,7 @@ void ColliderDetector::setBody(cpBody *pBody) ssize_t num = contourData->vertexList.size(); auto vs = contourData->vertexList; - cpVect *verts = new cpVect[num]; + cpVect *verts = new (std::nothrow) cpVect[num]; for (int i = 0; i < num; i++) { verts[num - 1 - i].x = vs.at(i).x; diff --git a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp index db2b87cdf9..077d19c8d3 100644 --- a/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp +++ b/cocos/editor-support/cocostudio/CCDataReaderHelper.cpp @@ -373,7 +373,7 @@ void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const if (_asyncStructQueue == nullptr) { _asyncStructQueue = new std::queue(); - _dataQueue = new std::queue(); + _dataQueue = new (std::nothrow) std::queue(); // create a new thread to load images _loadingThread = new std::thread(&DataReaderHelper::loadData, this); @@ -1644,7 +1644,7 @@ FrameData *DataReaderHelper::decodeFrame(const rapidjson::Value& json, DataInfo int length = DICTOOL->getArrayCount_json(json, A_EASING_PARAM); if (length != 0) { - frameData->easingParams = new float[length]; + frameData->easingParams = new (std::nothrow) float[length]; frameData->easingParamNumber = length; for (int i = 0; i < length; i++) @@ -2384,7 +2384,7 @@ void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, int count = pFrameDataArray[i].GetChildNum(); if (count != 0 ) { - frameData->easingParams = new float[count]; + frameData->easingParams = new (std::nothrow) float[count]; stExpCocoNode *pFrameData = pFrameDataArray[i].GetChildArray(cocoLoader); for (int ii = 0; ii < count; ++ii) { diff --git a/cocos/editor-support/cocostudio/CCDatas.cpp b/cocos/editor-support/cocostudio/CCDatas.cpp index 33fda0a4d3..d7c5c76ce4 100644 --- a/cocos/editor-support/cocostudio/CCDatas.cpp +++ b/cocos/editor-support/cocostudio/CCDatas.cpp @@ -283,7 +283,7 @@ void FrameData::copy(const BaseData *baseData) CC_SAFE_DELETE(easingParams); if (easingParamNumber != 0) { - easingParams = new float[easingParamNumber]; + easingParams = new (std::nothrow) float[easingParamNumber]; for (int i = 0; ieasingParams[i]; diff --git a/cocos/editor-support/cocostudio/CCDatas.h b/cocos/editor-support/cocostudio/CCDatas.h index b650df984f..c3d01de0f5 100644 --- a/cocos/editor-support/cocostudio/CCDatas.h +++ b/cocos/editor-support/cocostudio/CCDatas.h @@ -39,7 +39,7 @@ THE SOFTWARE. #define CC_CREATE_NO_PARAM_NO_INIT(varType)\ public: \ static inline varType *create(void){ \ - varType *var = new varType();\ + varType *var = new (std::nothrow) varType();\ if (var)\ {\ var->autorelease();\ @@ -52,7 +52,7 @@ public: \ #define CC_CREATE_NO_PARAM(varType)\ public: \ static inline varType *create(void){ \ - varType *var = new varType();\ + varType *var = new (std::nothrow) varType();\ if (var && var->init())\ {\ var->autorelease();\ diff --git a/cocos/editor-support/cocostudio/CocoLoader.cpp b/cocos/editor-support/cocostudio/CocoLoader.cpp index 5cef34224c..d6c5ab4c64 100644 --- a/cocos/editor-support/cocostudio/CocoLoader.cpp +++ b/cocos/editor-support/cocostudio/CocoLoader.cpp @@ -177,7 +177,7 @@ bool CocoLoader::ReadCocoBinBuff(char* pBinBuff) pTempBuff += sizeof(stCocoFileHeader); char* pStartAddr = m_pMemoryBuff = pTempBuff; - char* pDestBuff = new char[m_pFileHeader->m_nDataSize]; + char* pDestBuff = new (std::nothrow) char[m_pFileHeader->m_nDataSize]; if (m_pFileHeader->m_nCompressSize > 0) { uLongf dwSrcSize = m_pFileHeader->m_nCompressSize; diff --git a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp index 6f4b3178f0..efd9ddae63 100644 --- a/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp +++ b/cocos/editor-support/cocostudio/FlatBuffersSerialize.cpp @@ -119,7 +119,7 @@ FlatBuffersSerialize* FlatBuffersSerialize::getInstance() { if (!_instanceFlatBuffersSerialize) { - _instanceFlatBuffersSerialize = new FlatBuffersSerialize(); + _instanceFlatBuffersSerialize = new (std::nothrow) FlatBuffersSerialize(); } return _instanceFlatBuffersSerialize; @@ -161,7 +161,7 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str std::string content = FileUtils::getInstance()->getStringFromFile(inFullpath); // xml parse - tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument(); + tinyxml2::XMLDocument* document = new (std::nothrow) tinyxml2::XMLDocument(); document->Parse(content.c_str()); const tinyxml2::XMLElement* rootElement = document->RootElement();// Root @@ -238,7 +238,7 @@ std::string FlatBuffersSerialize::serializeFlatBuffersWithXMLFile(const std::str if (serializeEnabled) { - _builder = new FlatBufferBuilder(); + _builder = new (std::nothrow) FlatBufferBuilder(); Offset nodeTree; Offset aciton; @@ -1292,7 +1292,7 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato std::string content = FileUtils::getInstance()->getStringFromFile(inFullpath); // xml parse - tinyxml2::XMLDocument* document = new tinyxml2::XMLDocument(); + tinyxml2::XMLDocument* document = new (std::nothrow) tinyxml2::XMLDocument(); document->Parse(content.c_str()); const tinyxml2::XMLElement* rootElement = document->RootElement();// Root @@ -1345,7 +1345,7 @@ FlatBufferBuilder* FlatBuffersSerialize::createFlatBuffersWithXMLFileForSimulato if (serializeEnabled) { - _builder = new FlatBufferBuilder(); + _builder = new (std::nothrow) FlatBufferBuilder(); Offset nodeTree; Offset aciton; diff --git a/cocos/editor-support/cocostudio/TriggerBase.cpp b/cocos/editor-support/cocostudio/TriggerBase.cpp index 81931cb4e4..fed2934135 100755 --- a/cocos/editor-support/cocostudio/TriggerBase.cpp +++ b/cocos/editor-support/cocostudio/TriggerBase.cpp @@ -29,10 +29,10 @@ using namespace cocostudio; void sendEvent(unsigned int event) { - char* buf = new char[10]; + char buf[10]; sprintf(buf, "%d", event); std::string custom_event_name(buf); - CC_SAFE_DELETE_ARRAY(buf); + EventCustom eventCustom(custom_event_name); TriggerMng::getInstance()->dispatchEvent(&eventCustom); } diff --git a/cocos/editor-support/cocostudio/TriggerBase.h b/cocos/editor-support/cocostudio/TriggerBase.h index 1498a098fb..dedc3fc70e 100755 --- a/cocos/editor-support/cocostudio/TriggerBase.h +++ b/cocos/editor-support/cocostudio/TriggerBase.h @@ -40,7 +40,7 @@ THE SOFTWARE. #define IMPLEMENT_CLASS_INFO(className) \ cocos2d::Ref* className::createInstance(void) \ { \ - auto ret = new className; \ + auto ret = new (std::nothrow) className; \ ret->autorelease(); \ return ret; \ } \ diff --git a/cocos/editor-support/cocostudio/TriggerMng.cpp b/cocos/editor-support/cocostudio/TriggerMng.cpp index 4fcd142ead..cf0156eb04 100755 --- a/cocos/editor-support/cocostudio/TriggerMng.cpp +++ b/cocos/editor-support/cocostudio/TriggerMng.cpp @@ -491,7 +491,7 @@ void TriggerMng::addEventListenerWithFixedPriority(cocos2d::EventListener* liste ArmatureMovementDispatcher::ArmatureMovementDispatcher(void) : _mapEventAnimation(nullptr) { - _mapEventAnimation = new std::unordered_map ; + _mapEventAnimation = new (std::nothrow) std::unordered_map ; } ArmatureMovementDispatcher::~ArmatureMovementDispatcher(void) diff --git a/cocos/editor-support/cocostudio/TriggerObj.cpp b/cocos/editor-support/cocostudio/TriggerObj.cpp index 018c4b468c..7dd22cae4a 100755 --- a/cocos/editor-support/cocostudio/TriggerObj.cpp +++ b/cocos/editor-support/cocostudio/TriggerObj.cpp @@ -224,10 +224,9 @@ void TriggerObj::serialize(const rapidjson::Value &val) continue; } - char* buf = new char[10]; + char buf[10]; sprintf(buf, "%d", event); std::string custom_event_name(buf); - CC_SAFE_DELETE_ARRAY(buf); EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){ if (detect()) @@ -316,10 +315,9 @@ void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stEx { continue; } - char* buf = new char[10]; + char buf[10]; sprintf(buf, "%d", event); std::string custom_event_name(buf); - CC_SAFE_DELETE_ARRAY(buf); EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){ if (detect()) diff --git a/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp index b367709f92..449e8df93e 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/GameMapReader/GameMapReader.cpp @@ -55,7 +55,7 @@ namespace cocostudio { if (!_instanceTMXTiledMapReader) { - _instanceTMXTiledMapReader = new GameMapReader(); + _instanceTMXTiledMapReader = new (std::nothrow) GameMapReader(); } return _instanceTMXTiledMapReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp index de9859804c..2fe55b9409 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/GameNode3DReader/GameNode3DReader.cpp @@ -57,7 +57,7 @@ namespace cocostudio { if (!_instanceNode3DReader) { - _instanceNode3DReader = new GameNode3DReader(); + _instanceNode3DReader = new (std::nothrow) GameNode3DReader(); } return _instanceNode3DReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/Light3DReader/Light3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/Light3DReader/Light3DReader.cpp index ddf93a29a4..bcb8c281ad 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/Light3DReader/Light3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/Light3DReader/Light3DReader.cpp @@ -56,7 +56,7 @@ namespace cocostudio { if (!_instanceLight3DReader) { - _instanceLight3DReader = new Light3DReader(); + _instanceLight3DReader = new (std::nothrow) Light3DReader(); } return _instanceLight3DReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp index 5435505e48..cf9bcd09f9 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/Node3DReader/Node3DReader.cpp @@ -56,7 +56,7 @@ namespace cocostudio { if (!_instanceNode3DReader) { - _instanceNode3DReader = new Node3DReader(); + _instanceNode3DReader = new (std::nothrow) Node3DReader(); } return _instanceNode3DReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp index 07ef8b6159..8b060d0bb0 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/NodeReader/NodeReader.cpp @@ -73,7 +73,7 @@ namespace cocostudio { if (!_instanceNodeReader) { - _instanceNodeReader = new NodeReader(); + _instanceNodeReader = new (std::nothrow) NodeReader(); } return _instanceNodeReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/Particle3DReader/Particle3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/Particle3DReader/Particle3DReader.cpp index 84d814c781..1b5b0dddaa 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/Particle3DReader/Particle3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/Particle3DReader/Particle3DReader.cpp @@ -57,7 +57,7 @@ namespace cocostudio { if (!_instanceParticle3DReader) { - _instanceParticle3DReader = new Particle3DReader(); + _instanceParticle3DReader = new (std::nothrow) Particle3DReader(); } return _instanceParticle3DReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp index 9e27769f0d..13e35aa1e8 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ParticleReader/ParticleReader.cpp @@ -53,7 +53,7 @@ namespace cocostudio { if (!_instanceParticleReader) { - _instanceParticleReader = new ParticleReader(); + _instanceParticleReader = new (std::nothrow) ParticleReader(); } return _instanceParticleReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp index fe9d9cfdfb..83e880c883 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ProjectNodeReader/ProjectNodeReader.cpp @@ -51,7 +51,7 @@ namespace cocostudio { if (!_instanceProjectNodeReader) { - _instanceProjectNodeReader = new ProjectNodeReader(); + _instanceProjectNodeReader = new (std::nothrow) ProjectNodeReader(); } return _instanceProjectNodeReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/SingleNodeReader/SingleNodeReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SingleNodeReader/SingleNodeReader.cpp index b041da0164..6540ec4c03 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SingleNodeReader/SingleNodeReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SingleNodeReader/SingleNodeReader.cpp @@ -56,7 +56,7 @@ namespace cocostudio { if (!_instanceSingleNodeReader) { - _instanceSingleNodeReader = new SingleNodeReader(); + _instanceSingleNodeReader = new (std::nothrow) SingleNodeReader(); } return _instanceSingleNodeReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/Sprite3DReader/Sprite3DReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/Sprite3DReader/Sprite3DReader.cpp index c4745ef483..a145174910 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/Sprite3DReader/Sprite3DReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/Sprite3DReader/Sprite3DReader.cpp @@ -56,7 +56,7 @@ namespace cocostudio { if (!_instanceSprite3DReader) { - _instanceSprite3DReader = new Sprite3DReader(); + _instanceSprite3DReader = new (std::nothrow) Sprite3DReader(); } return _instanceSprite3DReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp index 269dfe462c..b293bdef9b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/SpriteReader/SpriteReader.cpp @@ -54,7 +54,7 @@ namespace cocostudio { if (!_instanceSpriteReader) { - _instanceSpriteReader = new SpriteReader(); + _instanceSpriteReader = new (std::nothrow) SpriteReader(); } return _instanceSpriteReader; diff --git a/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp index 6d9336a4e8..4ccdd4414d 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/UserCameraReader/UserCameraReader.cpp @@ -56,7 +56,7 @@ namespace cocostudio { if (!_instanceUserCameraReader) { - _instanceUserCameraReader = new UserCameraReader(); + _instanceUserCameraReader = new (std::nothrow) UserCameraReader(); } return _instanceUserCameraReader; diff --git a/cocos/navmesh/CCNavMesh.cpp b/cocos/navmesh/CCNavMesh.cpp index 7aef89301e..eb7d712115 100644 --- a/cocos/navmesh/CCNavMesh.cpp +++ b/cocos/navmesh/CCNavMesh.cpp @@ -183,9 +183,9 @@ bool NavMesh::loadNavMeshFile() return false; } - _allocator = new LinearAllocator(32000); - _compressor = new FastLZCompressor; - _meshProcess = new MeshProcess(_geomData); + _allocator = new (std::nothrow) LinearAllocator(32000); + _compressor = new (std::nothrow) FastLZCompressor; + _meshProcess = new (std::nothrow) MeshProcess(_geomData); status = _tileCache->init(&header.cacheParams, _allocator, _compressor, _meshProcess); if (dtStatusFailed(status)) @@ -233,7 +233,7 @@ bool NavMesh::loadGeomFile() auto data = FileUtils::getInstance()->getDataFromFile(_geomFilePath); if (data.isNull()) return false; buf = data.getBytes(); - _geomData = new GeomData; + _geomData = new (std::nothrow) GeomData; _geomData->offMeshConCount = 0; unsigned char* src = buf; diff --git a/cocos/navmesh/CCNavMeshDebugDraw.cpp b/cocos/navmesh/CCNavMeshDebugDraw.cpp index 459c655e64..8e392a2b82 100644 --- a/cocos/navmesh/CCNavMeshDebugDraw.cpp +++ b/cocos/navmesh/CCNavMeshDebugDraw.cpp @@ -93,7 +93,7 @@ void NavMeshDebugDraw::depthMask(bool state) void NavMeshDebugDraw::begin(duDebugDrawPrimitives prim, float size /*= 1.0f*/) { if (_currentPrimitive) return; - _currentPrimitive = new Primitive; + _currentPrimitive = new (std::nothrow) Primitive; _currentPrimitive->type = getPrimitiveType(prim); _currentPrimitive->depthMask = _currentDepthMask; _currentPrimitive->start = _vertices.size(); diff --git a/cocos/network/CCDownloader-apple.mm b/cocos/network/CCDownloader-apple.mm index 40aa2b06aa..e759aa70b4 100644 --- a/cocos/network/CCDownloader-apple.mm +++ b/cocos/network/CCDownloader-apple.mm @@ -104,7 +104,7 @@ namespace cocos2d { namespace network { } IDownloadTask *DownloaderApple::createCoTask(std::shared_ptr& task) { - DownloadTaskApple* coTask = new DownloadTaskApple(); + DownloadTaskApple* coTask = new (std::nothrow) DownloadTaskApple(); DeclareDownloaderImplVar; if (task->storagePath.length()) { diff --git a/cocos/network/CCDownloader-curl.cpp b/cocos/network/CCDownloader-curl.cpp index b052d1f9fd..44c98e6af4 100644 --- a/cocos/network/CCDownloader-curl.cpp +++ b/cocos/network/CCDownloader-curl.cpp @@ -740,7 +740,7 @@ namespace cocos2d { namespace network { IDownloadTask *DownloaderCURL::createCoTask(std::shared_ptr& task) { - DownloadTaskCURL *coTask = new DownloadTaskCURL; + DownloadTaskCURL *coTask = new (std::nothrow) DownloadTaskCURL; coTask->init(task->storagePath, _impl->hints.tempFileNameSuffix); DLLOG(" DownloaderCURL: createTask: Id(%d)", coTask->serialId); diff --git a/cocos/network/CCDownloader.cpp b/cocos/network/CCDownloader.cpp index 1ddcd534f6..105b0cfd28 100644 --- a/cocos/network/CCDownloader.cpp +++ b/cocos/network/CCDownloader.cpp @@ -130,7 +130,7 @@ namespace cocos2d { namespace network { std::shared_ptr Downloader::createDownloadDataTask(const std::string& srcUrl, const std::string& identifier/* = ""*/) { - DownloadTask *task_ = new DownloadTask(); + DownloadTask *task_ = new (std::nothrow) DownloadTask(); std::shared_ptr task(task_); do { @@ -155,7 +155,7 @@ namespace cocos2d { namespace network { const std::string& storagePath, const std::string& identifier/* = ""*/) { - DownloadTask *task_ = new DownloadTask(); + DownloadTask *task_ = new (std::nothrow) DownloadTask(); std::shared_ptr task(task_); do { diff --git a/cocos/network/HttpClient-winrt.cpp b/cocos/network/HttpClient-winrt.cpp index 84878b7270..e1c6c3ca7b 100644 --- a/cocos/network/HttpClient-winrt.cpp +++ b/cocos/network/HttpClient-winrt.cpp @@ -78,7 +78,7 @@ namespace network { static void processHttpResponse(HttpResponse* response, std::string& errorStr); - static HttpRequest *s_requestSentinel = new HttpRequest; + static HttpRequest *s_requestSentinel = new (std::nothrow) HttpRequest; // Worker thread void HttpClient::networkThread() diff --git a/cocos/network/SocketIO.cpp b/cocos/network/SocketIO.cpp index 5d662ebc65..6030d719aa 100644 --- a/cocos/network/SocketIO.cpp +++ b/cocos/network/SocketIO.cpp @@ -308,10 +308,10 @@ SocketIOPacket * SocketIOPacket::createPacketWithType(std::string type, SocketIO switch (version) { case SocketIOPacket::SocketIOVersion::V09x: - ret = new SocketIOPacket; + ret = new (std::nothrow) SocketIOPacket; break; case SocketIOPacket::SocketIOVersion::V10x: - ret = new SocketIOPacketV10x; + ret = new (std::nothrow) SocketIOPacketV10x; break; } ret->initWithType(type); @@ -325,10 +325,10 @@ SocketIOPacket * SocketIOPacket::createPacketWithTypeIndex(int type, SocketIOPac switch (version) { case SocketIOPacket::SocketIOVersion::V09x: - ret = new SocketIOPacket; + ret = new (std::nothrow) SocketIOPacket; break; case SocketIOPacket::SocketIOVersion::V10x: - return new SocketIOPacketV10x; + return new (std::nothrow) SocketIOPacketV10x; break; } ret->initWithTypeIndex(type); diff --git a/cocos/network/WebSocket.cpp b/cocos/network/WebSocket.cpp index b61c592589..fdac3e435a 100644 --- a/cocos/network/WebSocket.cpp +++ b/cocos/network/WebSocket.cpp @@ -120,8 +120,8 @@ WsThreadHelper::WsThreadHelper() , _ws(nullptr) , _needQuit(false) { - _UIWsMessageQueue = new std::list(); - _subThreadWsMessageQueue = new std::list(); + _UIWsMessageQueue = new (std::nothrow) std::list(); + _subThreadWsMessageQueue = new (std::nothrow) std::list(); Director::getInstance()->getScheduler()->scheduleUpdate(this, 0, false); } @@ -140,7 +140,7 @@ bool WsThreadHelper::createThread(const WebSocket& ws) _ws = const_cast(&ws); // Creates websocket thread - _subThreadInstance = new std::thread(&WsThreadHelper::wsThreadEntryFunc, this); + _subThreadInstance = new (std::nothrow) std::thread(&WsThreadHelper::wsThreadEntryFunc, this); return true; } @@ -309,7 +309,7 @@ bool WebSocket::init(const Delegate& delegate, protocolCount = 1; } - _wsProtocols = new libwebsocket_protocols[protocolCount+1]; + _wsProtocols = new (std::nothrow) libwebsocket_protocols[protocolCount+1]; memset(_wsProtocols, 0, sizeof(libwebsocket_protocols)*(protocolCount+1)); if (protocols && protocols->size() > 0) @@ -317,7 +317,7 @@ bool WebSocket::init(const Delegate& delegate, int i = 0; for (std::vector::const_iterator iter = protocols->begin(); iter != protocols->end(); ++iter, ++i) { - char* name = new char[(*iter).length()+1]; + char* name = new (std::nothrow) char[(*iter).length()+1]; strcpy(name, (*iter).c_str()); _wsProtocols[i].name = name; _wsProtocols[i].callback = WebSocketCallbackWrapper::onSocketCallback; @@ -325,7 +325,7 @@ bool WebSocket::init(const Delegate& delegate, } else { - char* name = new char[20]; + char* name = new (std::nothrow) char[20]; strcpy(name, "default-protocol"); _wsProtocols[0].name = name; _wsProtocols[0].callback = WebSocketCallbackWrapper::onSocketCallback; @@ -346,7 +346,7 @@ void WebSocket::send(const std::string& message) WsMessage* msg = new (std::nothrow) WsMessage(); msg->what = WS_MSG_TO_SUBTRHEAD_SENDING_STRING; Data* data = new (std::nothrow) Data(); - data->bytes = new char[message.length()+1]; + data->bytes = new (std::nothrow) char[message.length()+1]; strcpy(data->bytes, message.c_str()); data->len = static_cast(message.length()); msg->obj = data; @@ -364,7 +364,7 @@ void WebSocket::send(const unsigned char* binaryMsg, unsigned int len) WsMessage* msg = new (std::nothrow) WsMessage(); msg->what = WS_MSG_TO_SUBTRHEAD_SENDING_BINARY; Data* data = new (std::nothrow) Data(); - data->bytes = new char[len]; + data->bytes = new (std::nothrow) char[len]; memcpy((void*)data->bytes, (void*)binaryMsg, len); data->len = len; msg->obj = data; @@ -546,7 +546,7 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, //fixme: the log is not thread safe // CCLOG("[websocket:send] total: %d, sent: %d, remaining: %d, buffer size: %d", static_cast(data->len), static_cast(data->issued), static_cast(remaining), static_cast(n)); - unsigned char* buf = new unsigned char[LWS_SEND_BUFFER_PRE_PADDING + n + LWS_SEND_BUFFER_POST_PADDING]; + unsigned char* buf = new (std::nothrow) unsigned char[LWS_SEND_BUFFER_PRE_PADDING + n + LWS_SEND_BUFFER_POST_PADDING]; memcpy((char*)&buf[LWS_SEND_BUFFER_PRE_PADDING], data->bytes + data->issued, n); @@ -630,13 +630,13 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, // Accumulate the data (increasing the buffer as we go) if (_currentDataLen == 0) { - _currentData = new char[len]; + _currentData = new (std::nothrow) char[len]; memcpy (_currentData, in, len); _currentDataLen = len; } else { - char *new_data = new char [_currentDataLen + len]; + char *new_data = new (std::nothrow) char [_currentDataLen + len]; memcpy (new_data, _currentData, _currentDataLen); memcpy (new_data + _currentDataLen, in, len); CC_SAFE_DELETE_ARRAY(_currentData); @@ -663,12 +663,12 @@ int WebSocket::onSocketCallback(struct libwebsocket_context *ctx, if (lws_frame_is_binary(wsi)) { - bytes = new char[_currentDataLen]; + bytes = new (std::nothrow) char[_currentDataLen]; data->isBinary = true; } else { - bytes = new char[_currentDataLen+1]; + bytes = new (std::nothrow) char[_currentDataLen+1]; bytes[_currentDataLen] = '\0'; data->isBinary = false; } diff --git a/cocos/physics/CCPhysicsShape.cpp b/cocos/physics/CCPhysicsShape.cpp index ed67ab6e05..aebc09a57c 100644 --- a/cocos/physics/CCPhysicsShape.cpp +++ b/cocos/physics/CCPhysicsShape.cpp @@ -271,7 +271,7 @@ void PhysicsShape::setSensor(bool sensor) void PhysicsShape::recenterPoints(Vec2* points, int count, const Vec2& center) { - cpVect* cpvs = new cpVect[count]; + cpVect* cpvs = new (std::nothrow) cpVect[count]; cpRecenterPoly(count, PhysicsHelper::points2cpvs(points, cpvs, count)); PhysicsHelper::cpvs2points(cpvs, points, count); delete[] cpvs; @@ -287,7 +287,7 @@ void PhysicsShape::recenterPoints(Vec2* points, int count, const Vec2& center) Vec2 PhysicsShape::getPolyonCenter(const Vec2* points, int count) { - cpVect* cpvs = new cpVect[count]; + cpVect* cpvs = new (std::nothrow) cpVect[count]; cpVect center = cpCentroidForPoly(count, PhysicsHelper::points2cpvs(points, cpvs, count)); delete[] cpvs; @@ -550,7 +550,7 @@ bool PhysicsShapePolygon::init(const Vec2* points, int count, const PhysicsMater { _type = Type::POLYGEN; - auto vecs = new cpVect[count]; + auto vecs = new (std::nothrow) cpVect[count]; PhysicsHelper::points2cpvs(points, vecs, count); auto shape = cpPolyShapeNew(s_sharedBody, count, vecs, PhysicsHelper::point2cpv(offset)); CC_SAFE_DELETE_ARRAY(vecs); @@ -573,7 +573,7 @@ bool PhysicsShapePolygon::init(const Vec2* points, int count, const PhysicsMater float PhysicsShapePolygon::calculateArea(const Vec2* points, int count) { - cpVect* vecs = new cpVect[count]; + cpVect* vecs = new (std::nothrow) cpVect[count]; PhysicsHelper::points2cpvs(points, vecs, count); float area = PhysicsHelper::cpfloat2float(cpAreaForPoly(count, vecs)); CC_SAFE_DELETE_ARRAY(vecs); @@ -583,7 +583,7 @@ float PhysicsShapePolygon::calculateArea(const Vec2* points, int count) float PhysicsShapePolygon::calculateMoment(float mass, const Vec2* points, int count, const Vec2& offset) { - cpVect* vecs = new cpVect[count]; + cpVect* vecs = new (std::nothrow) cpVect[count]; PhysicsHelper::points2cpvs(points, vecs, count); float moment = mass == PHYSICS_INFINITY ? PHYSICS_INFINITY : PhysicsHelper::cpfloat2float(cpMomentForPoly(mass, count, vecs, PhysicsHelper::point2cpv(offset))); @@ -735,7 +735,7 @@ bool PhysicsShapeEdgePolygon::init(const Vec2* points, int count, const PhysicsM { _type = Type::EDGEPOLYGEN; - vec = new cpVect[count]; + vec = new (std::nothrow) cpVect[count]; PhysicsHelper::points2cpvs(points, vec, count); int i = 0; @@ -767,7 +767,7 @@ bool PhysicsShapeEdgePolygon::init(const Vec2* points, int count, const PhysicsM Vec2 PhysicsShapeEdgePolygon::getCenter() { int count = (int)_cpShapes.size(); - cpVect* points = new cpVect[count]; + cpVect* points = new (std::nothrow) cpVect[count]; int i = 0; for(auto shape : _cpShapes) { @@ -834,7 +834,7 @@ bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMat { _type = Type::EDGECHAIN; - vec = new cpVect[count]; + vec = new (std::nothrow) cpVect[count]; PhysicsHelper::points2cpvs(points, vec, count); int i = 0; @@ -865,7 +865,7 @@ bool PhysicsShapeEdgeChain::init(const Vec2* points, int count, const PhysicsMat Vec2 PhysicsShapeEdgeChain::getCenter() { int count = (int)_cpShapes.size() + 1; - cpVect* points = new cpVect[count]; + cpVect* points = new (std::nothrow) cpVect[count]; int i = 0; for(auto shape : _cpShapes) { diff --git a/cocos/physics3d/CCPhysicsSprite3D.cpp b/cocos/physics3d/CCPhysicsSprite3D.cpp index 98ef95645c..e004f19acf 100644 --- a/cocos/physics3d/CCPhysicsSprite3D.cpp +++ b/cocos/physics3d/CCPhysicsSprite3D.cpp @@ -32,7 +32,7 @@ NS_CC_BEGIN PhysicsSprite3D* PhysicsSprite3D::create(const std::string &modelPath, Physics3DRigidBodyDes* rigidDes, const cocos2d::Vec3& translateInPhysics, const cocos2d::Quaternion& rotInPhsyics) { - auto ret = new PhysicsSprite3D(); + auto ret = new (std::nothrow) PhysicsSprite3D(); if (ret && ret->initWithFile(modelPath)) { auto obj = Physics3DRigidBody::create(rigidDes); diff --git a/cocos/platform/CCImage.cpp b/cocos/platform/CCImage.cpp index 08f2f2d601..f06dc4d364 100644 --- a/cocos/platform/CCImage.cpp +++ b/cocos/platform/CCImage.cpp @@ -869,7 +869,7 @@ bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID contai { bpp = 3; saveLen = _width * _height * bpp; - pSaveData = new unsigned char[saveLen]; + pSaveData = new (std::nothrow) unsigned char[saveLen]; int indL = 0, indR = 0; while (indL < saveLen && indR < _dataLen) @@ -881,7 +881,7 @@ bool Image::encodeWithWIC(const std::string& filePath, bool isToRGB, GUID contai } else { - pSaveData = new unsigned char[saveLen]; + pSaveData = new (std::nothrow) unsigned char[saveLen]; memcpy(pSaveData, _data, saveLen); } @@ -1456,7 +1456,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen) CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; _mipmaps[_numberOfMipmaps].len = width*height*4; - _mipmaps[_numberOfMipmaps].address = new unsigned char[width*height*4]; + _mipmaps[_numberOfMipmaps].address = new (std::nothrow) unsigned char[width*height*4]; PVRTDecompressPVRTC(_data+dataOffset,width,height,_mipmaps[_numberOfMipmaps].address, true); bpp = 2; } @@ -1470,7 +1470,7 @@ bool Image::initWithPVRv2Data(const unsigned char * data, ssize_t dataLen) CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; _mipmaps[_numberOfMipmaps].len = width*height*4; - _mipmaps[_numberOfMipmaps].address = new unsigned char[width*height*4]; + _mipmaps[_numberOfMipmaps].address = new (std::nothrow) unsigned char[width*height*4]; PVRTDecompressPVRTC(_data+dataOffset,width,height,_mipmaps[_numberOfMipmaps].address, false); bpp = 4; } @@ -1612,7 +1612,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; _mipmaps[i].len = width*height*4; - _mipmaps[i].address = new unsigned char[width*height*4]; + _mipmaps[i].address = new (std::nothrow) unsigned char[width*height*4]; PVRTDecompressPVRTC(_data+dataOffset,width,height,_mipmaps[i].address, true); bpp = 2; } @@ -1627,7 +1627,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) CCLOG("cocos2d: Hardware PVR decoder not present. Using software decoder"); _unpack = true; _mipmaps[i].len = width*height*4; - _mipmaps[i].address = new unsigned char[width*height*4]; + _mipmaps[i].address = new (std::nothrow) unsigned char[width*height*4]; PVRTDecompressPVRTC(_data+dataOffset,width,height,_mipmaps[i].address, false); bpp = 4; } @@ -1643,7 +1643,7 @@ bool Image::initWithPVRv3Data(const unsigned char * data, ssize_t dataLen) unsigned int stride = width * bytePerPixel; _unpack = true; _mipmaps[i].len = width*height*bytePerPixel; - _mipmaps[i].address = new unsigned char[width*height*bytePerPixel]; + _mipmaps[i].address = new (std::nothrow) unsigned char[width*height*bytePerPixel]; if (etc1_decode_image(static_cast(_data+dataOffset), static_cast(_mipmaps[i].address), width, height, bytePerPixel, stride) != 0) { return false; diff --git a/cocos/platform/ios/CCDevice-ios.mm b/cocos/platform/ios/CCDevice-ios.mm index 4ac08929c6..5ea7bb2e87 100644 --- a/cocos/platform/ios/CCDevice-ios.mm +++ b/cocos/platform/ios/CCDevice-ios.mm @@ -72,7 +72,7 @@ static CCAccelerometerDispatcher* s_pAccelerometerDispatcher; - (id) init { if( (self = [super init]) ) { - _acceleration = new cocos2d::Acceleration(); + _acceleration = new (std::nothrow) cocos2d::Acceleration(); _motionManager = [[CMMotionManager alloc] init]; _motionManager.accelerometerUpdateInterval = SENSOR_DELAY_GAME; } diff --git a/cocos/platform/ios/CCImage-ios.mm b/cocos/platform/ios/CCImage-ios.mm index d9a0dad034..ec1923b01e 100644 --- a/cocos/platform/ios/CCImage-ios.mm +++ b/cocos/platform/ios/CCImage-ios.mm @@ -65,7 +65,7 @@ bool cocos2d::Image::saveToFile(const std::string& filename, bool isToRGB) // or want to save as jpg, remove the alpha channel. if (hasAlpha() && bitsPerPixel == 24) { - pixels = new unsigned char[myDataLength]; + pixels = new (std::nothrow) unsigned char[myDataLength]; for (int i = 0; i < _height; ++i) { diff --git a/cocos/renderer/CCGLProgramCache.cpp b/cocos/renderer/CCGLProgramCache.cpp index 007588d6ee..207daec8c6 100644 --- a/cocos/renderer/CCGLProgramCache.cpp +++ b/cocos/renderer/CCGLProgramCache.cpp @@ -237,43 +237,43 @@ void GLProgramCache::loadDefaultGLPrograms() loadDefaultGLProgram(p, kShaderType_3DSkinPositionTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_TEXTURE, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DPositionNormal); _programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NORMAL, p) ); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DPositionNormalTex); _programs.insert( std::make_pair(GLProgram::SHADER_3D_POSITION_NORMAL_TEXTURE, p) ); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionNormalTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_NORMAL_TEXTURE, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DPositionBumpedNormalTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_POSITION_BUMPEDNORMAL_TEXTURE, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DSkinPositionBumpedNormalTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKINPOSITION_BUMPEDNORMAL_TEXTURE, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DParticleColor); _programs.insert(std::make_pair(GLProgram::SHADER_3D_PARTICLE_COLOR, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DParticleTex); _programs.insert(std::make_pair(GLProgram::SHADER_3D_PARTICLE_TEXTURE, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DSkyBox); _programs.insert(std::make_pair(GLProgram::SHADER_3D_SKYBOX, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_3DTerrain); _programs.insert(std::make_pair(GLProgram::SHADER_3D_TERRAIN, p)); - p = new GLProgram(); + p = new (std::nothrow) GLProgram(); loadDefaultGLProgram(p, kShaderType_CameraClear); _programs.insert(std::make_pair(GLProgram::SHADER_CAMERA_CLEAR, p)); } diff --git a/cocos/renderer/CCGLProgramState.cpp b/cocos/renderer/CCGLProgramState.cpp index 120950c7b4..97241793d0 100644 --- a/cocos/renderer/CCGLProgramState.cpp +++ b/cocos/renderer/CCGLProgramState.cpp @@ -155,7 +155,7 @@ void UniformValue::setCallback(const std::function & if (_type == Type::CALLBACK_FN) delete _value.callback; - _value.callback = new std::function(); + _value.callback = new (std::nothrow) std::function(); *_value.callback = callback; _type = Type::CALLBACK_FN; @@ -290,7 +290,7 @@ void VertexAttribValue::apply() void VertexAttribValue::setCallback(const std::function &callback) { - _value.callback = new std::function(); + _value.callback = new (std::nothrow) std::function(); *_value.callback = callback; _useCallback = true; _enabled = true; diff --git a/cocos/renderer/CCTexture2D.cpp b/cocos/renderer/CCTexture2D.cpp index 189d01a6a3..49273110e6 100644 --- a/cocos/renderer/CCTexture2D.cpp +++ b/cocos/renderer/CCTexture2D.cpp @@ -1392,7 +1392,7 @@ void Texture2D::addSpriteFrameCapInset(SpriteFrame* spritframe, const Rect& capI { if(nullptr == _ninePatchInfo) { - _ninePatchInfo = new NinePatchInfo; + _ninePatchInfo = new (std::nothrow) NinePatchInfo; } if(nullptr == spritframe) { diff --git a/cocos/renderer/CCTextureCache.cpp b/cocos/renderer/CCTextureCache.cpp index bfbf59cfd2..fc7f950f48 100644 --- a/cocos/renderer/CCTextureCache.cpp +++ b/cocos/renderer/CCTextureCache.cpp @@ -154,7 +154,7 @@ void TextureCache::addImageAsync(const std::string &path, const std::functionfullPathForFilename(dstName); Texture2D* tex = it->second; - Image* image = new Image(); + Image* image = new (std::nothrow) Image(); if (image) { bool ret = image->initWithImageFile(dstName); diff --git a/cocos/renderer/CCTextureCube.cpp b/cocos/renderer/CCTextureCube.cpp index 17fd54bd64..60d049561f 100644 --- a/cocos/renderer/CCTextureCube.cpp +++ b/cocos/renderer/CCTextureCube.cpp @@ -68,7 +68,7 @@ unsigned char* getImageData(Image* img, Texture2D::PixelFormat& ePixFmt) { // Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRGGGGGGBBBBB" inPixel32 = (unsigned int*)img->getData(); - pTmpData = new unsigned char[nWidth * nHeight * 2]; + pTmpData = new (std::nothrow) unsigned char[nWidth * nHeight * 2]; outPixel16 = (unsigned short*)pTmpData; for (unsigned int i = 0; i < uLen; ++i, ++inPixel32) @@ -82,7 +82,7 @@ unsigned char* getImageData(Image* img, Texture2D::PixelFormat& ePixFmt) else { // Convert "RRRRRRRRGGGGGGGGBBBBBBBB" to "RRRRRGGGGGGBBBBB" - pTmpData = new unsigned char[nWidth * nHeight * 2]; + pTmpData = new (std::nothrow) unsigned char[nWidth * nHeight * 2]; outPixel16 = (unsigned short*)pTmpData; inPixel8 = (unsigned char*)img->getData(); @@ -105,7 +105,7 @@ unsigned char* getImageData(Image* img, Texture2D::PixelFormat& ePixFmt) // Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRRRRRGGGGGGGGBBBBBBBB" inPixel32 = (unsigned int*)img->getData(); - pTmpData = new unsigned char[nWidth * nHeight * 3]; + pTmpData = new (std::nothrow) unsigned char[nWidth * nHeight * 3]; unsigned char* outPixel8 = pTmpData; for (unsigned int i = 0; i < uLen; ++i, ++inPixel32) diff --git a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp index 72e6fd78a9..6620835d41 100644 --- a/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp +++ b/cocos/scripting/js-bindings/manual/3d/jsb_cocos2dx_3d_manual.cpp @@ -79,7 +79,7 @@ static bool js_cocos2dx_Sprite3D_createAsync(JSContext *cx, uint32_t argc, jsval }; callback = lambda; - JSB_HeapValueWrapper* data = new JSB_HeapValueWrapper(cx, args.get(argc == 4 ? 3 : 4)); + JSB_HeapValueWrapper* data = new (std::nothrow) JSB_HeapValueWrapper(cx, args.get(argc == 4 ? 3 : 4)); if(argc == 4) cocos2d::Sprite3D::createAsync(modelPath, callback, data); diff --git a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp index aab6456212..19e1a2cd8c 100644 --- a/cocos/scripting/js-bindings/manual/ScriptingCore.cpp +++ b/cocos/scripting/js-bindings/manual/ScriptingCore.cpp @@ -454,7 +454,7 @@ ScriptingCore* ScriptingCore::getInstance() { static ScriptingCore* instance = nullptr; if (instance == nullptr) - instance = new ScriptingCore(); + instance = new (std::nothrow) ScriptingCore(); return instance; } @@ -475,7 +475,7 @@ ScriptingCore::ScriptingCore() void ScriptingCore::initRegister() { this->addRegisterCallback(registerDefaultClasses); - this->_runLoop = new SimpleRunLoop(); + this->_runLoop = new (std::nothrow) SimpleRunLoop(); } void ScriptingCore::string_report(JS::HandleValue val) { diff --git a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp index 936430eff6..2bf73aada1 100644 --- a/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp +++ b/cocos/scripting/js-bindings/manual/chipmunk/js_bindings_chipmunk_manual.cpp @@ -38,7 +38,7 @@ void static freeSpaceChildren(cpSpace *space); template static bool dummy_constructor(JSContext *cx, uint32_t argc, jsval *vp) { TypeTest t; - T* cobj = new T(); + T* cobj = new (std::nothrow) T(); cobj->autorelease(); js_type_class_t *p; std::string typeName = t.s_name(); @@ -483,7 +483,7 @@ bool JSPROXY_CCPhysicsSprite_spriteWithSpriteFrameName__static(JSContext *cx, ui bool JSPROXY_CCPhysicsSprite_constructor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); bool ok = true; - PhysicsSprite* cobj = new PhysicsSprite(); + PhysicsSprite* cobj = new (std::nothrow) PhysicsSprite(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); @@ -511,7 +511,7 @@ static bool JSPROXY_CCPhysicsSprite_ctor(JSContext *cx, uint32_t argc, jsval *vp { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - PhysicsSprite *nobj = new PhysicsSprite(); + PhysicsSprite *nobj = new (std::nothrow) PhysicsSprite(); if (nobj) { nobj->autorelease(); } @@ -951,7 +951,7 @@ void JSB_cpSpace_finalize(JSFreeOp *fop, JSObject *jsthis) static bool __jsb_cpSpace_addCollisionHandler(JSContext *cx, jsval *vp, jsval *argvp, JS::HandleObject jsspace, cpSpace *space, unsigned int is_oo) { - struct collision_handler *handler = new collision_handler(); + struct collision_handler *handler = new (std::nothrow) collision_handler(); handler->typeA = 0; handler->typeB = 0; @@ -1048,7 +1048,7 @@ bool JSB_cpSpace_setDefaultCollisionHandler(JSContext *cx, uint32_t argc, jsval struct jsb_c_proxy_s* proxy = jsb_get_c_proxy_for_jsobject(jsthis); cpSpace* space = (cpSpace*) proxy->handle; - collision_handler *handler = new collision_handler(); + collision_handler *handler = new (std::nothrow) collision_handler(); JSB_PRECONDITION(handler, "Error allocating memory"); handler->typeA = 0; @@ -1367,7 +1367,7 @@ bool JSB_cpSpace_segmentQueryFirst(JSContext *cx, uint32_t argc, jsval *vp){ ok &= jsval_to_uint( cx, args.get(3), (unsigned int*)&group ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); - cpSegmentQueryInfo *out = new cpSegmentQueryInfo(); + cpSegmentQueryInfo *out = new (std::nothrow) cpSegmentQueryInfo(); cpShape* target = cpSpaceSegmentQueryFirst(space, start, end, layers, group, out); if(target) @@ -1405,7 +1405,7 @@ bool JSB_cpSpace_nearestPointQueryNearest(JSContext *cx, uint32_t argc, jsval *v ok &= jsval_to_uint( cx, args.get(3), (unsigned int*)&group ); JSB_PRECONDITION2(ok, cx, false, "Error processing arguments"); - cpNearestPointQueryInfo* info = new cpNearestPointQueryInfo(); + cpNearestPointQueryInfo* info = new (std::nothrow) cpNearestPointQueryInfo(); cpShape* target = cpSpaceNearestPointQueryNearest(space, point, maxDistance, layers, group, info); if(target) diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp index 0f4c728ab2..3822df0696 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.cpp @@ -537,7 +537,7 @@ bool js_cocos2dx_JSTouchDelegate_registerStandardDelegate(JSContext *cx, uint32_ { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSTouchDelegate *touch = new JSTouchDelegate(); + JSTouchDelegate *touch = new (std::nothrow) JSTouchDelegate(); int priority = 1; if (argc == 2) @@ -562,7 +562,7 @@ bool js_cocos2dx_JSTouchDelegate_registerTargetedDelegate(JSContext *cx, uint32_ { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - JSTouchDelegate *touch = new JSTouchDelegate(); + JSTouchDelegate *touch = new (std::nothrow) JSTouchDelegate(); touch->registerTargetedDelegate(args.get(0).toInt32(), args.get(1).toBoolean()); JS::RootedObject jsobj(cx, args.get(2).toObjectOrNull()); @@ -807,7 +807,7 @@ void JSScheduleWrapper::setTargetForSchedule(JS::HandleValue sched, JSScheduleWr JSObject* jsfunc = sched.toObjectOrNull(); auto targetArray = getTargetForSchedule(sched); if (NULL == targetArray) { - targetArray = new __Array(); + targetArray = new (std::nothrow) __Array(); targetArray->init(); schedFunc_proxy_t *p = (schedFunc_proxy_t *)malloc(sizeof(schedFunc_proxy_t)); assert(p); @@ -834,7 +834,7 @@ void JSScheduleWrapper::setTargetForJSObject(JS::HandleObject jsTargetObj, JSSch { auto targetArray = getTargetForJSObject(jsTargetObj); if (NULL == targetArray) { - targetArray = new __Array(); + targetArray = new (std::nothrow) __Array(); targetArray->init(); schedTarget_proxy_t *p = (schedTarget_proxy_t *)malloc(sizeof(schedTarget_proxy_t)); assert(p); @@ -1255,7 +1255,7 @@ bool js_CCNode_scheduleOnce(JSContext *cx, uint32_t argc, jsval *vp) if (!bFound) { - tmpCobj = new JSScheduleWrapper(); + tmpCobj = new (std::nothrow) JSScheduleWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(thisValue); tmpCobj->setJSCallbackFunc(args.get(0)); @@ -1351,7 +1351,7 @@ bool js_CCNode_schedule(JSContext *cx, uint32_t argc, jsval *vp) if (!bFound) { - tmpCobj = new JSScheduleWrapper(); + tmpCobj = new (std::nothrow) JSScheduleWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(thisValue); tmpCobj->setJSCallbackFunc(args.get(0)); @@ -1425,7 +1425,7 @@ bool js_cocos2dx_CCNode_scheduleUpdateWithPriority(JSContext *cx, uint32_t argc, if (!bFound) { - tmpCobj = new JSScheduleWrapper(); + tmpCobj = new (std::nothrow) JSScheduleWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(thisValue); tmpCobj->setJSCallbackFunc(jsUpdateFunc); @@ -1526,7 +1526,7 @@ bool js_cocos2dx_CCNode_scheduleUpdate(JSContext *cx, uint32_t argc, jsval *vp) if (!bFound) { - tmpCobj = new JSScheduleWrapper(); + tmpCobj = new (std::nothrow) JSScheduleWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(thisValue); tmpCobj->setJSCallbackFunc(jsUpdateFunc); @@ -1641,7 +1641,7 @@ bool js_CCScheduler_scheduleUpdateForTarget(JSContext *cx, uint32_t argc, jsval if (!bFound) { - tmpCObj = new JSScheduleWrapper(); + tmpCObj = new (std::nothrow) JSScheduleWrapper(); tmpCObj->autorelease(); tmpCObj->setJSCallbackThis(args.get(0)); tmpCObj->setJSCallbackFunc(jsUpdateFunc); @@ -1767,7 +1767,7 @@ bool js_CCScheduler_scheduleCallbackForTarget(JSContext *cx, uint32_t argc, jsva if (!bFound) { - tmpCObj = new JSScheduleWrapper(); + tmpCObj = new (std::nothrow) JSScheduleWrapper(); tmpCObj->autorelease(); tmpCObj->setJSCallbackThis(args.get(0)); tmpCObj->setJSCallbackFunc(args.get(1)); @@ -5643,7 +5643,7 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval std::string arg0; ok &= jsval_to_std_string(cx, args.get(0), &arg0); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); @@ -5657,7 +5657,7 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval ok &= jsval_to_std_string(cx, args.get(0), &arg0); ok &= jsval_to_ccrect(cx, args.get(1), &arg1); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); @@ -5673,7 +5673,7 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval ok &= jsval_to_ccrect(cx, args.get(1), &arg1); ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); @@ -5691,7 +5691,7 @@ bool js_cocos2dx_AutoPolygon_generatePolygon(JSContext *cx, uint32_t argc, jsval ok &= JS::ToNumber( cx, args.get(2), &arg2) && !isnan(arg2); ok &= JS::ToNumber( cx, args.get(3), &arg3) && !isnan(arg3); JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_AutoPolygon_generatePolygon : Error processing arguments"); - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3)); jsval jsret = JSVAL_NULL; if (ret) { jsret = OBJECT_TO_JSVAL(js_get_or_create_jsobject(cx, ret)); diff --git a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp index 1c6dc8ff2c..e770ad9ea6 100644 --- a/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp +++ b/cocos/scripting/js-bindings/manual/cocos2d_specifics.hpp @@ -270,7 +270,7 @@ public: static __JSPlistDelegator* getInstance() { static __JSPlistDelegator* pInstance = NULL; if (pInstance == NULL) { - pInstance = new __JSPlistDelegator(); + pInstance = new (std::nothrow) __JSPlistDelegator(); } return pInstance; }; diff --git a/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp b/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp index bf8d014297..6c910a1530 100644 --- a/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp +++ b/cocos/scripting/js-bindings/manual/cocosbuilder/js_bindings_ccbreader.cpp @@ -64,7 +64,7 @@ void CCBScriptCallbackProxy::onNodeLoaded(Node * pNode, NodeLoader * pNodeLoader) {} CCBSelectorResolver * CCBScriptCallbackProxy::createNew() { - CCBScriptCallbackProxy * ret = new CCBScriptCallbackProxy(); + CCBScriptCallbackProxy * ret = new (std::nothrow) CCBScriptCallbackProxy(); ret->setJSOwner(this->owner); return dynamic_cast(ret); } @@ -99,7 +99,7 @@ bool js_cocos2dx_CCBAnimationManager_animationCompleteCallback(JSContext *cx, ui js_proxy_t *p = jsb_get_js_proxy(obj); cocosbuilder::CCBAnimationManager *node = (cocosbuilder::CCBAnimationManager *)(p ? p->ptr : NULL); - JSCCBAnimationWrapper *tmpCobj = new JSCCBAnimationWrapper(); + JSCCBAnimationWrapper *tmpCobj = new (std::nothrow) JSCCBAnimationWrapper(); tmpCobj->autorelease(); tmpCobj->setJSCallbackThis(args.get(0)); @@ -289,7 +289,7 @@ bool js_CocosBuilder_create(JSContext *cx, uint32_t argc, jsval *vp) ccNodeLoaderLibrary->registerNodeLoader("", JSLayerLoader::loader()); - CCBReader * ret = new CCBReader(ccNodeLoaderLibrary); + CCBReader * ret = new (std::nothrow) CCBReader(ccNodeLoaderLibrary); ret->autorelease(); jsval jsret; diff --git a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp index 0923abf765..0263abaebc 100644 --- a/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp +++ b/cocos/scripting/js-bindings/manual/cocostudio/jsb_cocos2dx_studio_manual.cpp @@ -115,7 +115,7 @@ static bool js_cocos2dx_ArmatureAnimation_setMovementEventCallFunc(JSContext *cx return true; } else if (argc == 1 || argc == 2) { - JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); + JSArmatureWrapper *tmpObj = new (std::nothrow) JSArmatureWrapper(); tmpObj->autorelease(); cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); @@ -161,7 +161,7 @@ static bool js_cocos2dx_ArmatureAnimation_setFrameEventCallFunc(JSContext *cx, u return true; } else if (argc == 1 || argc == 2) { - JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); + JSArmatureWrapper *tmpObj = new (std::nothrow) JSArmatureWrapper(); tmpObj->autorelease(); cocos2d::__Dictionary* dict = static_cast(cobj->getUserObject()); @@ -202,7 +202,7 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 3) { - JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); + JSArmatureWrapper *tmpObj = new (std::nothrow) JSArmatureWrapper(); tmpObj->autorelease(); tmpObj->setJSCallbackFunc(args.get(1)); @@ -217,7 +217,7 @@ static bool jsb_Animation_addArmatureFileInfoAsyncCallFunc(JSContext *cx, uint32 } if(argc == 5){ - JSArmatureWrapper *tmpObj = new JSArmatureWrapper(); + JSArmatureWrapper *tmpObj = new (std::nothrow) JSArmatureWrapper(); tmpObj->autorelease(); tmpObj->setJSCallbackFunc(args.get(3)); diff --git a/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp b/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp index 3e76c6d114..174a9100ae 100644 --- a/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp +++ b/cocos/scripting/js-bindings/manual/component/CCComponentJS.cpp @@ -73,7 +73,7 @@ ComponentJS::ComponentJS(const std::string& scriptFileName) CCASSERT(typeMapIter != _js_global_type_map.end(), "Can't find the class type!"); typeClass = typeMapIter->second; - mozilla::Maybe *jsObj = new mozilla::Maybe(); + mozilla::Maybe *jsObj = new (std::nothrow) mozilla::Maybe(); JS::RootedObject proto(cx, protoValue.toObjectOrNull()); JS::RootedObject parent(cx, typeClass->proto.ref()); diff --git a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp index f0ac2167cd..72ce50f4f3 100644 --- a/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/js-bindings/manual/extension/jsb_cocos2dx_extension_manual.cpp @@ -86,7 +86,7 @@ static bool js_cocos2dx_CCScrollView_setDelegate(JSContext *cx, uint32_t argc, j { // save the delegate JS::RootedObject jsDelegate(cx, args.get(0).toObjectOrNull()); - JSB_ScrollViewDelegate* nativeDelegate = new JSB_ScrollViewDelegate(); + JSB_ScrollViewDelegate* nativeDelegate = new (std::nothrow) JSB_ScrollViewDelegate(); nativeDelegate->setJSDelegate(jsDelegate); cobj->setUserObject(nativeDelegate); @@ -196,13 +196,13 @@ static bool js_cocos2dx_CCTableView_setDelegate(JSContext *cx, uint32_t argc, js { // save the delegate JS::RootedObject jsDelegate(cx, args.get(0).toObjectOrNull()); - JSB_TableViewDelegate* nativeDelegate = new JSB_TableViewDelegate(); + JSB_TableViewDelegate* nativeDelegate = new (std::nothrow) JSB_TableViewDelegate(); nativeDelegate->setJSDelegate(jsDelegate); __Dictionary* userDict = static_cast<__Dictionary*>(cobj->getUserObject()); if (NULL == userDict) { - userDict = new __Dictionary(); + userDict = new (std::nothrow) __Dictionary(); cobj->setUserObject(userDict); userDict->release(); } @@ -376,14 +376,14 @@ static bool js_cocos2dx_CCTableView_setDataSource(JSContext *cx, uint32_t argc, JSB_PRECONDITION2( cobj, cx, false, "Invalid Native Object"); if (argc == 1) { - JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); + JSB_TableViewDataSource* pNativeSource = new (std::nothrow) JSB_TableViewDataSource(); JS::RootedObject jsdata(cx, args.get(0).toObjectOrNull()); pNativeSource->setTableViewDataSource(jsdata); __Dictionary* userDict = static_cast<__Dictionary*>(cobj->getUserObject()); if (NULL == userDict) { - userDict = new __Dictionary(); + userDict = new (std::nothrow) __Dictionary(); cobj->setUserObject(userDict); userDict->release(); } @@ -409,14 +409,14 @@ static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval * if (argc == 3 || argc == 2) { - JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); + JSB_TableViewDataSource* pNativeSource = new (std::nothrow) JSB_TableViewDataSource(); JS::RootedObject jsdata(cx, args.get(0).toObjectOrNull()); pNativeSource->setTableViewDataSource(jsdata); cocos2d::Size arg1; ok &= jsval_to_ccsize(cx, args.get(1), &arg1); cocos2d::extension::TableView* ret = NULL; - ret = new TableView(); + ret = new (std::nothrow) TableView(); ret->autorelease(); ret->setDataSource(pNativeSource); @@ -454,7 +454,7 @@ static bool js_cocos2dx_CCTableView_create(JSContext *cx, uint32_t argc, jsval * } ret->reloadData(); - __Dictionary* userDict = new __Dictionary(); + __Dictionary* userDict = new (std::nothrow) __Dictionary(); userDict->setObject(pNativeSource, KEY_TABLEVIEW_DATA_SOURCE); ret->setUserObject(userDict); userDict->release(); @@ -480,7 +480,7 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp if (argc == 3 || argc == 2) { - JSB_TableViewDataSource* pNativeSource = new JSB_TableViewDataSource(); + JSB_TableViewDataSource* pNativeSource = new (std::nothrow) JSB_TableViewDataSource(); JS::RootedObject jsdata(cx, args.get(0).toObjectOrNull()); pNativeSource->setTableViewDataSource(jsdata); cobj->setDataSource(pNativeSource); @@ -507,7 +507,7 @@ static bool js_cocos2dx_CCTableView_init(JSContext *cx, uint32_t argc, jsval *vp } cobj->reloadData(); - __Dictionary* userDict = new __Dictionary(); + __Dictionary* userDict = new (std::nothrow) __Dictionary(); userDict->setObject(pNativeSource, KEY_TABLEVIEW_DATA_SOURCE); cobj->setUserObject(userDict); userDict->release(); @@ -583,7 +583,7 @@ public: CC_SAFE_DELETE(_callback); } JSContext* cx = ScriptingCore::getInstance()->getGlobalContext(); - _callback = new JSFunctionWrapper(cx, jsTarget, jsFunc); + _callback = new (std::nothrow) JSFunctionWrapper(cx, jsTarget, jsFunc); _jsFunc.ref() = jsFunc.toObjectOrNull(); } @@ -631,7 +631,7 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext } // save the delegate - JSB_ControlButtonTarget* nativeDelegate = new JSB_ControlButtonTarget(); + JSB_ControlButtonTarget* nativeDelegate = new (std::nothrow) JSB_ControlButtonTarget(); JS::RootedObject jscb(cx, jsDelegate); nativeDelegate->setJSCallback(args.get(1), jscb); @@ -640,7 +640,7 @@ static bool js_cocos2dx_CCControl_addTargetWithActionForControlEvents(JSContext __Array* nativeDelegateArray = static_cast<__Array*>(cobj->getUserObject()); if (nullptr == nativeDelegateArray) { - nativeDelegateArray = new __Array(); + nativeDelegateArray = new (std::nothrow) __Array(); nativeDelegateArray->init(); cobj->setUserObject(nativeDelegateArray); // The reference of nativeDelegateArray is added to 2 nativeDelegateArray->release(); // Release nativeDelegateArray to make the reference to 1 diff --git a/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp b/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp index 605bc616fd..22c48e6a26 100644 --- a/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp +++ b/cocos/scripting/js-bindings/manual/js_bindings_opengl.cpp @@ -70,7 +70,7 @@ bool js_cocos2dx_GLNode_constructor(JSContext *cx, uint32_t argc, jsval *vp) { if (argc == 0) { - cocos2d::GLNode* cobj = new cocos2d::GLNode(); + cocos2d::GLNode* cobj = new (std::nothrow) cocos2d::GLNode(); cocos2d::Ref *_ccobj = dynamic_cast(cobj); if (_ccobj) { _ccobj->autorelease(); @@ -108,7 +108,7 @@ static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); JS::RootedObject obj(cx, args.thisv().toObjectOrNull()); - cocos2d::GLNode *nobj = new cocos2d::GLNode(); + cocos2d::GLNode *nobj = new (std::nothrow) cocos2d::GLNode(); js_proxy_t* p = jsb_new_proxy(nobj, obj); nobj->autorelease(); JS::AddNamedObjectRoot(cx, &p->obj, "GLNode"); @@ -119,7 +119,7 @@ static bool js_cocos2dx_GLNode_ctor(JSContext *cx, uint32_t argc, jsval *vp) bool js_cocos2dx_GLNode_create(JSContext *cx, uint32_t argc, jsval *vp) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - cocos2d::GLNode* ret = new cocos2d::GLNode(); + cocos2d::GLNode* ret = new (std::nothrow) cocos2d::GLNode(); jsval jsret; do { if (ret) { diff --git a/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp b/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp index 9a41cf9eea..0c46b02993 100644 --- a/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp +++ b/cocos/scripting/js-bindings/manual/js_manual_conversions.cpp @@ -937,7 +937,7 @@ bool jsval_to_ccarray_of_CCPoint(JSContext* cx, JS::HandleValue v, Point **point uint32_t len; JS_GetArrayLength(cx, jsobj, &len); - Point *array = new Point[len]; + Point *array = new (std::nothrow) Point[len]; for( uint32_t i=0; i< len;i++ ) { JS::RootedValue valarg(cx); diff --git a/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp b/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp index eb8f4edd0c..f6036b3264 100644 --- a/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp +++ b/cocos/scripting/js-bindings/manual/jsb_opengl_manual.cpp @@ -194,7 +194,7 @@ bool JSB_glGetProgramInfoLog(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetProgramiv(arg0, GL_INFO_LOG_LENGTH, &length); - GLchar* src = new GLchar[length]; + GLchar* src = new (std::nothrow) GLchar[length]; glGetProgramInfoLog(arg0, length, NULL, src); args.rval().set(charptr_to_jsval(cx, src)); @@ -215,7 +215,7 @@ bool JSB_glGetShaderInfoLog(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetShaderiv(arg0, GL_INFO_LOG_LENGTH, &length); - GLchar* src = new GLchar[length]; + GLchar* src = new (std::nothrow) GLchar[length]; glGetShaderInfoLog(arg0, length, NULL, src); args.rval().set(charptr_to_jsval(cx, src)); @@ -236,7 +236,7 @@ bool JSB_glGetShaderSource(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetShaderiv(arg0, GL_SHADER_SOURCE_LENGTH, &length); - GLchar* src = new GLchar[length]; + GLchar* src = new (std::nothrow) GLchar[length]; glGetShaderSource(arg0, length, NULL, src); args.rval().set(charptr_to_jsval(cx, src)); @@ -262,7 +262,7 @@ bool JSB_glGetActiveAttrib(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetProgramiv(arg0, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &length); - GLchar* buffer = new GLchar[length]; + GLchar* buffer = new (std::nothrow) GLchar[length]; GLint size = -1; GLenum type = -1; @@ -306,7 +306,7 @@ bool JSB_glGetActiveUniform(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetProgramiv(arg0, GL_ACTIVE_ATTRIBUTE_MAX_LENGTH, &length); - GLchar* buffer = new GLchar[length]; + GLchar* buffer = new (std::nothrow) GLchar[length]; GLint size = -1; GLenum type = -1; @@ -344,7 +344,7 @@ bool JSB_glGetAttachedShaders(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetProgramiv(arg0, GL_ATTACHED_SHADERS, &length); - GLuint* buffer = new GLuint[length]; + GLuint* buffer = new (std::nothrow) GLuint[length]; memset(buffer, 0, length * sizeof(GLuint)); //Fix bug 2448, it seems that glGetAttachedShaders will crash if we send NULL to the third parameter (eg Windows), same as in lua binding GLsizei realShaderCount = 0; @@ -376,7 +376,7 @@ bool JSB_glGetSupportedExtensions(JSContext *cx, uint32_t argc, jsval *vp) // copy, to be able to add '\0' size_t len = strlen((char*)extensions); - GLubyte* copy = new GLubyte[len+1]; + GLubyte* copy = new (std::nothrow) GLubyte[len+1]; strncpy((char*)copy, (const char*)extensions, len ); int start_extension=0; @@ -438,7 +438,7 @@ bool JSB_glGetUniformfv(JSContext *cx, uint32_t argc, jsval *vp) GLsizei length; glGetProgramiv(arg0, GL_ACTIVE_UNIFORM_MAX_LENGTH, &length); - GLchar* namebuffer = new GLchar[length+1]; + GLchar* namebuffer = new (std::nothrow) GLchar[length+1]; GLint size = -1; GLenum type = -1; @@ -520,7 +520,7 @@ bool JSB_glGetUniformfv(JSContext *cx, uint32_t argc, jsval *vp) // FIXME: glew on windows will cause array overflow after invoking glGetUniformfv. // It seems that glGetUniformfv re-assign the memeroy with a wrong size which is 4x than we pass in. // For temporary solution, we allocate 4x array. - GLfloat* param = new GLfloat[usize*4]; + GLfloat* param = new (std::nothrow) GLfloat[usize*4]; glGetUniformfv(arg0, arg1, param); typedArray = JS_NewFloat32Array(cx, usize); @@ -531,7 +531,7 @@ bool JSB_glGetUniformfv(JSContext *cx, uint32_t argc, jsval *vp) // FIXME: glew on windows will cause array overflow after invoking glGetUniformfv. // It seems that glGetUniformfv re-assign the memeroy with a wrong size which is 4x than we pass in. // For temporary solution, we allocate 4x array. - GLint* param = new GLint[usize*4]; + GLint* param = new (std::nothrow) GLint[usize*4]; glGetUniformiv(arg0, arg1, param); typedArray = JS_NewInt32Array(cx, usize); diff --git a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp index e072836378..3f5de58d1c 100644 --- a/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp +++ b/cocos/scripting/js-bindings/manual/network/XMLHTTPRequest.cpp @@ -44,7 +44,7 @@ void MinXmlHttpRequest::_gotHeader(string header) { // Get Header and Set StatusText // Split String into Tokens - char * cstr = new char [header.length()+1]; + char * cstr = new (std::nothrow) char [header.length()+1]; // check for colon. size_t found_header_field = header.find_first_of(":"); @@ -335,7 +335,7 @@ JS_BINDED_CLASS_GLUE_IMPL(MinXmlHttpRequest); JS_BINDED_CONSTRUCTOR_IMPL(MinXmlHttpRequest) { JS::CallArgs args = JS::CallArgsFromVp(argc, vp); - MinXmlHttpRequest* req = new MinXmlHttpRequest(); + MinXmlHttpRequest* req = new (std::nothrow) MinXmlHttpRequest(); req->autorelease(); js_proxy_t *p; diff --git a/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp b/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp index 886254a0a0..210dcf1c26 100644 --- a/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp +++ b/cocos/scripting/js-bindings/manual/network/jsb_socketio.cpp @@ -153,7 +153,7 @@ bool js_cocos2dx_SocketIO_connect(JSContext* cx, uint32_t argc, jsval* vp) JSB_PRECONDITION2( ok, cx, false, "Error processing arguments"); } while (0); - JSB_SocketIODelegate* siodelegate = new JSB_SocketIODelegate(); + JSB_SocketIODelegate* siodelegate = new (std::nothrow) JSB_SocketIODelegate(); CCLOG("Calling native SocketIO.connect method"); SIOClient* ret = SocketIO::connect(url, *siodelegate); diff --git a/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp b/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp index fcaffca5ed..aa330e84a8 100644 --- a/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp +++ b/cocos/scripting/js-bindings/manual/network/jsb_websocket.cpp @@ -268,8 +268,8 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j JS::RootedObject obj(cx, JS_NewObject(cx, js_cocos2dx_websocket_class, proto, JS::NullPtr())); //JS::RootedObject obj(cx, JS_NewObjectForConstructor(cx, js_cocos2dx_websocket_class, args)); - WebSocket* cobj = new WebSocket(); - JSB_WebSocketDelegate* delegate = new JSB_WebSocketDelegate(); + WebSocket* cobj = new (std::nothrow) WebSocket(); + JSB_WebSocketDelegate* delegate = new (std::nothrow) JSB_WebSocketDelegate(); delegate->setJSDelegate(obj); if (argc == 2) diff --git a/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm b/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm index 700865d94f..9834c20c31 100644 --- a/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm +++ b/cocos/scripting/js-bindings/manual/platform/ios/JavaScriptObjCBridge.mm @@ -206,7 +206,7 @@ void JavaScriptObjCBridge::CallInfo::pushValue(void *val){ else if ([oval isKindOfClass:[NSString class]]) { const char *content = [oval cStringUsingEncoding:NSUTF8StringEncoding]; - m_ret.stringValue = new string(content); + m_ret.stringValue = new (std::nothrow) string(content); m_returnType = TypeString; } else if ([oval isKindOfClass:[NSDictionary class]]) @@ -232,7 +232,7 @@ JS_BINDED_CLASS_GLUE_IMPL(JavaScriptObjCBridge); */ JS_BINDED_CONSTRUCTOR_IMPL(JavaScriptObjCBridge) { - JavaScriptObjCBridge* jsj = new JavaScriptObjCBridge(); + JavaScriptObjCBridge* jsj = new (std::nothrow) JavaScriptObjCBridge(); js_proxy_t *p; jsval out; diff --git a/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp b/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp index c8836a4a4f..1bf9f8d8e5 100755 --- a/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp +++ b/cocos/scripting/js-bindings/manual/ui/jsb_cocos2dx_ui_manual.cpp @@ -184,7 +184,7 @@ static bool js_cocos2dx_CCEditBox_setDelegate(JSContext *cx, uint32_t argc, jsva if (argc == 1) { // save the delegate - JSB_EditBoxDelegate* nativeDelegate = new JSB_EditBoxDelegate(); + JSB_EditBoxDelegate* nativeDelegate = new (std::nothrow) JSB_EditBoxDelegate(); nativeDelegate->setJSDelegate(args.get(0)); cobj->setUserObject(nativeDelegate); diff --git a/cocos/scripting/lua-bindings/manual/3d/lua_cocos2dx_3d_manual.cpp b/cocos/scripting/lua-bindings/manual/3d/lua_cocos2dx_3d_manual.cpp index 1fae2d5b69..a0d93aac8e 100644 --- a/cocos/scripting/lua-bindings/manual/3d/lua_cocos2dx_3d_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/3d/lua_cocos2dx_3d_manual.cpp @@ -977,7 +977,7 @@ int lua_cocos2dx_3d_AABB_constructor(lua_State* L) ok &= luaval_to_vec3(L, 3, &arg1, "cc.AABB:AABB"); if (!ok) { break; } - cobj = new cocos2d::AABB(arg0, arg1); + cobj = new (std::nothrow) cocos2d::AABB(arg0, arg1); tolua_pushusertype(L,(void*)cobj,"cc.AABB"); tolua_register_gc(L,lua_gettop(L)); return 1; @@ -986,7 +986,7 @@ int lua_cocos2dx_3d_AABB_constructor(lua_State* L) ok = true; do{ if (argc == 0) { - cobj = new cocos2d::AABB(); + cobj = new (std::nothrow) cocos2d::AABB(); tolua_pushusertype(L,(void*)cobj,"cc.AABB"); tolua_register_gc(L,lua_gettop(L)); return 1; @@ -1381,7 +1381,7 @@ int lua_cocos2dx_3d_OBB_constructor(lua_State* L) ok &= luaval_to_object(L, 2, "cc.AABB",&arg0, "cc.OBB:OBB"); if (!ok) { break; } - cobj = new cocos2d::OBB(*arg0); + cobj = new (std::nothrow) cocos2d::OBB(*arg0); tolua_pushusertype(L,(void*)cobj,"cc.OBB"); tolua_register_gc(L,lua_gettop(L)); return 1; @@ -1390,7 +1390,7 @@ int lua_cocos2dx_3d_OBB_constructor(lua_State* L) ok = true; do{ if (argc == 0) { - cobj = new cocos2d::OBB(); + cobj = new (std::nothrow) cocos2d::OBB(); tolua_pushusertype(L,(void*)cobj,"cc.OBB"); tolua_register_gc(L,lua_gettop(L)); return 1; @@ -1407,7 +1407,7 @@ int lua_cocos2dx_3d_OBB_constructor(lua_State* L) ok &= luaval_to_int32(L, 3,(int *)&arg1, "cc.OBB:OBB"); if (!ok) { break; } - cobj = new cocos2d::OBB(arg0, arg1); + cobj = new (std::nothrow) cocos2d::OBB(arg0, arg1); tolua_pushusertype(L,(void*)cobj,"cc.OBB"); tolua_register_gc(L,lua_gettop(L)); return 1; @@ -1839,7 +1839,7 @@ int lua_cocos2dx_3d_OBB_getCorners(lua_State* L) return 0; } - arg0 = new cocos2d::Vec3[len]; + arg0 = new (std::nothrow) cocos2d::Vec3[len]; if (nullptr == arg0) { @@ -2075,7 +2075,7 @@ int lua_cocos2dx_3d_Ray_constructor(lua_State* L) ok &= luaval_to_vec3(L, 3, &arg1, "cc.Ray:Ray"); if (!ok) { break; } - cobj = new cocos2d::Ray(arg0, arg1); + cobj = new (std::nothrow) cocos2d::Ray(arg0, arg1); tolua_pushusertype(L,(void*)cobj,"cc.Ray"); tolua_register_gc(L,lua_gettop(L)); return 1; @@ -2084,7 +2084,7 @@ int lua_cocos2dx_3d_Ray_constructor(lua_State* L) ok = true; do{ if (argc == 0) { - cobj = new cocos2d::Ray(); + cobj = new (std::nothrow) cocos2d::Ray(); tolua_pushusertype(L,(void*)cobj,"cc.Ray"); tolua_register_gc(L,lua_gettop(L)); return 1; diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/LuaOpengl.cpp b/cocos/scripting/lua-bindings/manual/cocos2d/LuaOpengl.cpp index afc7c9e2e8..1389d3f592 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/LuaOpengl.cpp +++ b/cocos/scripting/lua-bindings/manual/cocos2d/LuaOpengl.cpp @@ -557,7 +557,7 @@ static int tolua_Cocos2d_glBufferData00(lua_State* tolua_S) { unsigned int target = (unsigned int)tolua_tonumber(tolua_S,1,0); long length = (long)tolua_tonumber(tolua_S,2,0); - float* floatArray = new float[length]; + float* floatArray = new (std::nothrow) float[length]; if (NULL == floatArray) { return 0; @@ -600,7 +600,7 @@ static int tolua_Cocos2d_glBufferSubData00(lua_State* tolua_S) unsigned int target = (unsigned int)tolua_tonumber(tolua_S,1,0); long offset = (long)tolua_tonumber(tolua_S,2,0); long length = (long)tolua_tonumber(tolua_S,3,0); - float* floatArray = new float[length]; + float* floatArray = new (std::nothrow) float[length]; if (NULL == floatArray) { return 0; @@ -850,7 +850,7 @@ static int tolua_Cocos2d_glCompressedTexImage2D00(lua_State* tolua_S) int imageSize = (int)tolua_tonumber(tolua_S, 7, 0); long length = (long)tolua_tonumber(tolua_S,8,0); - float* floatArray = new float[length]; + float* floatArray = new (std::nothrow) float[length]; if (NULL == floatArray) { return 0; @@ -905,7 +905,7 @@ static int tolua_Cocos2d_glCompressedTexSubImage2D00(lua_State* tolua_S) int imageSize = (int)tolua_tonumber(tolua_S, 8, 0); long length = (long)tolua_tonumber(tolua_S,9,0); - float* floatArray = new float[length]; + float* floatArray = new (std::nothrow) float[length]; if (NULL == floatArray) { return 0; @@ -1459,7 +1459,7 @@ static int tolua_Cocos2d_glDrawElements00(lua_State* tolua_S) { if (arg3 > 0) { - unsigned char* unit8Array = new unsigned char[arg3]; + unsigned char* unit8Array = new (std::nothrow) unsigned char[arg3]; if (NULL == unit8Array) { return 0; @@ -1481,7 +1481,7 @@ static int tolua_Cocos2d_glDrawElements00(lua_State* tolua_S) { if (arg3 > 0) { - unsigned short* shortArray = new unsigned short[arg3]; + unsigned short* shortArray = new (std::nothrow) unsigned short[arg3]; if (NULL == shortArray) { return 0; @@ -1504,8 +1504,8 @@ static int tolua_Cocos2d_glDrawElements00(lua_State* tolua_S) { if (arg3 > 0) { - unsigned int* intArray = new unsigned int[arg3]; - if (NULL == intArray) + unsigned int* intArray = new (std::nothrow) unsigned int[arg3]; + if (nullptr == intArray) { return 0; } @@ -2723,7 +2723,7 @@ static int tolua_Cocos2d_glReadPixels00(lua_State* tolua_S) unsigned int arg5 = (unsigned int)tolua_tonumber(tolua_S, 6, 0); long length = (long)tolua_tonumber(tolua_S,7,0); - unsigned char* unit8Array = new unsigned char[length]; + unsigned char* unit8Array = new (std::nothrow) unsigned char[length]; if (NULL == unit8Array) { return 0; @@ -3110,7 +3110,7 @@ static int tolua_Cocos2d_glTexImage2D00(lua_State* tolua_S) unsigned int arg7 = (unsigned int)tolua_tonumber(tolua_S, 8, 0); unsigned int arg8 = (unsigned int)tolua_tonumber(tolua_S, 9, 0); - unsigned char* unit8Array = new unsigned char[arg8]; + unsigned char* unit8Array = new (std::nothrow) unsigned char[arg8]; if (NULL == unit8Array) { return 0; @@ -3236,7 +3236,7 @@ static int tolua_Cocos2d_glTexSubImage2D00(lua_State* tolua_S) unsigned int arg7 = (unsigned int)tolua_tonumber(tolua_S, 8, 0); unsigned int arg8 = (unsigned int)tolua_tonumber(tolua_S, 9, 0); - unsigned char* unit8Array = new unsigned char[arg8]; + unsigned char* unit8Array = new (std::nothrow) unsigned char[arg8]; if (NULL == unit8Array) { return 0; @@ -3316,7 +3316,7 @@ static int tolua_Cocos2d_glUniform1fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -3385,7 +3385,7 @@ static int tolua_Cocos2d_glUniform1iv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - int* intArray = new int[arg2]; + int* intArray = new (std::nothrow) int[arg2]; if (NULL == intArray) { return 0; @@ -3456,7 +3456,7 @@ static int tolua_Cocos2d_glUniform2fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -3527,7 +3527,7 @@ static int tolua_Cocos2d_glUniform2iv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - int* intArray = new int[arg2]; + int* intArray = new (std::nothrow) int[arg2]; if (NULL == intArray) { return 0; @@ -3600,7 +3600,7 @@ static int tolua_Cocos2d_glUniform3fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -3673,7 +3673,7 @@ static int tolua_Cocos2d_glUniform3iv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - int* intArray = new int[arg2]; + int* intArray = new (std::nothrow) int[arg2]; if (NULL == intArray) { return 0; @@ -3748,7 +3748,7 @@ static int tolua_Cocos2d_glUniform4fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -3823,7 +3823,7 @@ static int tolua_Cocos2d_glUniform4iv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - int* intArray = new int[arg2]; + int* intArray = new (std::nothrow) int[arg2]; if (NULL == intArray) { return 0; @@ -3864,7 +3864,7 @@ static int tolua_Cocos2d_glUniformMatrix2fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); unsigned short arg1 = (unsigned short)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -3905,7 +3905,7 @@ static int tolua_Cocos2d_glUniformMatrix3fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); unsigned short arg1 = (unsigned short)tolua_tonumber(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -3948,7 +3948,7 @@ static int tolua_Cocos2d_glUniformMatrix4fv00(lua_State* tolua_S) int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); bool arg1 = (bool)tolua_toboolean(tolua_S, 2, 0); int arg2 = (int)tolua_tonumber(tolua_S, 3, 0); - float* floatArray = new float[arg2]; + float* floatArray = new (std::nothrow) float[arg2]; if (NULL == floatArray) { return 0; @@ -4069,7 +4069,7 @@ static int tolua_Cocos2d_glVertexAttrib1fv00(lua_State* tolua_S) { int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); - float* floatArray = new float[arg1]; + float* floatArray = new (std::nothrow) float[arg1]; if (NULL == floatArray) { return 0; @@ -4141,7 +4141,7 @@ static int tolua_Cocos2d_glVertexAttrib2fv00(lua_State* tolua_S) { int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); - float* floatArray = new float[arg1]; + float* floatArray = new (std::nothrow) float[arg1]; if (NULL == floatArray) { return 0; @@ -4215,7 +4215,7 @@ static int tolua_Cocos2d_glVertexAttrib3fv00(lua_State* tolua_S) { int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); - float* floatArray = new float[arg1]; + float* floatArray = new (std::nothrow) float[arg1]; if (NULL == floatArray) { return 0; @@ -4291,7 +4291,7 @@ static int tolua_Cocos2d_glVertexAttrib4fv00(lua_State* tolua_S) { int arg0 = (int)tolua_tonumber(tolua_S, 1, 0); int arg1 = (int)tolua_tonumber(tolua_S, 2, 0); - float* floatArray = new float[arg1]; + float* floatArray = new (std::nothrow) float[arg1]; if (NULL == floatArray) { return 0; @@ -4459,7 +4459,7 @@ CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawPoints00(lua if (numberOfPoints > 0) { - cocos2d::Vec2* points = new cocos2d::Vec2[numberOfPoints]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[numberOfPoints]; if (NULL == points) return 0; @@ -4621,7 +4621,7 @@ CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawPoly00(lua_S if (numOfVertices > 0) { - cocos2d::Vec2* points = new cocos2d::Vec2[numOfVertices]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[numOfVertices]; if (NULL == points) return 0; @@ -4675,7 +4675,7 @@ CC_DEPRECATED_ATTRIBUTE static int tolua_cocos2d_DrawPrimitives_drawSolidPoly00( unsigned int numberOfPoints = ((unsigned int) tolua_tonumber(tolua_S,2,0)); if (numberOfPoints > 0) { - cocos2d::Vec2* points = new cocos2d::Vec2[numberOfPoints]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[numberOfPoints]; if (NULL == points) return 0; diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_deprecated.cpp b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_deprecated.cpp index b72dfbb384..a2acf106e1 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_deprecated.cpp +++ b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_deprecated.cpp @@ -2767,7 +2767,7 @@ static int lua_cocos2dx_LabelBMFont_constructor(lua_State* tolua_S) { if(!ok) return 0; - cobj = new cocos2d::LabelBMFont(); + cobj = new (std::nothrow) cocos2d::LabelBMFont(); cobj->autorelease(); int ID = (int)cobj->_ID ; int* luaID = &cobj->_luaID ; @@ -4287,7 +4287,7 @@ static int lua_cocos2dx_LabelTTF_constructor(lua_State* tolua_S) { if(!ok) return 0; - cobj = new cocos2d::LabelTTF(); + cobj = new (std::nothrow) cocos2d::LabelTTF(); cobj->autorelease(); int ID = (int)cobj->_ID ; int* luaID = &cobj->_luaID ; diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp index 9a6f3b7449..e99544fa09 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_manual.cpp @@ -2948,7 +2948,7 @@ static int tolua_cocos2dx_DrawNode_drawPolygon(lua_State* tolua_S) size_t size = lua_tonumber(tolua_S, 3); if ( size > 0 ) { - cocos2d::Vec2* points = new cocos2d::Vec2[size]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[size]; if (NULL == points) return 0; @@ -3034,7 +3034,7 @@ int tolua_cocos2dx_DrawNode_drawSolidPoly(lua_State* tolua_S) luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawSolidPoly"); if ( size > 0 ) { - cocos2d::Vec2* points = new cocos2d::Vec2[size]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[size]; if (NULL == points) return 0; @@ -3113,7 +3113,7 @@ int tolua_cocos2dx_DrawNode_drawPoly(lua_State* tolua_S) luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawPoly"); if ( size > 0 ) { - cocos2d::Vec2* points = new cocos2d::Vec2[size]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[size]; if (NULL == points) return 0; @@ -3323,7 +3323,7 @@ int tolua_cocos2dx_DrawNode_drawPoints(lua_State* tolua_S) luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawPoints"); if ( size > 0 ) { - cocos2d::Vec2* points = new cocos2d::Vec2[size]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[size]; if (NULL == points) return 0; @@ -3363,7 +3363,7 @@ int tolua_cocos2dx_DrawNode_drawPoints(lua_State* tolua_S) luaval_to_uint32(tolua_S, 3, &size, "cc.DrawNode:drawPoints"); if ( size > 0 ) { - cocos2d::Vec2* points = new cocos2d::Vec2[size]; + cocos2d::Vec2* points = new (std::nothrow) cocos2d::Vec2[size]; if (nullptr == points) return 0; @@ -7155,7 +7155,7 @@ int lua_cocos2dx_TMXLayer_setTiles(lua_State* tolua_S) luaL_error(tolua_S, "Table's len equal 0"); return 0; } - arg0 = new uint32_t[len]; + arg0 = new (std::nothrow) uint32_t[len]; if (nullptr == arg0) { @@ -7774,7 +7774,7 @@ int lua_cocos2dx_AutoPolygon_generatePolygon(lua_State* tolua_S) tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_AutoPolygon_generatePolygon'", nullptr); return 0; } - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0)); object_to_luaval(tolua_S, "cc.PolygonInfo",(cocos2d::PolygonInfo*)ret); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); return 1; @@ -7790,7 +7790,7 @@ int lua_cocos2dx_AutoPolygon_generatePolygon(lua_State* tolua_S) tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_AutoPolygon_generatePolygon'", nullptr); return 0; } - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1)); object_to_luaval(tolua_S, "cc.PolygonInfo",(cocos2d::PolygonInfo*)ret); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); return 1; @@ -7808,7 +7808,7 @@ int lua_cocos2dx_AutoPolygon_generatePolygon(lua_State* tolua_S) tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_AutoPolygon_generatePolygon'", nullptr); return 0; } - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2)); object_to_luaval(tolua_S, "cc.PolygonInfo",(cocos2d::PolygonInfo*)ret); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); return 1; @@ -7828,7 +7828,7 @@ int lua_cocos2dx_AutoPolygon_generatePolygon(lua_State* tolua_S) tolua_error(tolua_S,"invalid arguments in function 'lua_cocos2dx_AutoPolygon_generatePolygon'", nullptr); return 0; } - cocos2d::PolygonInfo* ret = new cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3)); + cocos2d::PolygonInfo* ret = new (std::nothrow) cocos2d::PolygonInfo(cocos2d::AutoPolygon::generatePolygon(arg0, arg1, arg2, arg3)); object_to_luaval(tolua_S, "cc.PolygonInfo",(cocos2d::PolygonInfo*)ret); tolua_register_gc(tolua_S,lua_gettop(tolua_S)); return 1; diff --git a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_physics_manual.cpp b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_physics_manual.cpp index f8bfed42a8..a84971f4fa 100644 --- a/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_physics_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/cocos2d/lua_cocos2dx_physics_manual.cpp @@ -849,7 +849,7 @@ int lua_cocos2dx_physics_PhysicsShapePolygon_getPoints(lua_State* tolua_S) if (argc == 0) { int count = cobj->getPointsCount(); - cocos2d::Vec2* arg0 = new cocos2d::Vec2[count]; + cocos2d::Vec2* arg0 = new (std::nothrow) cocos2d::Vec2[count]; cobj->getPoints(arg0); vec2_array_to_luaval(tolua_S, arg0, count); CC_SAFE_DELETE_ARRAY(arg0); @@ -1090,7 +1090,7 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeBox_getPoints(lua_State* tolua_S) if (argc == 0) { int count = cobj->getPointsCount(); - cocos2d::Vec2* arg0 = new cocos2d::Vec2[count]; + cocos2d::Vec2* arg0 = new (std::nothrow) cocos2d::Vec2[count]; cobj->getPoints(arg0); vec2_array_to_luaval(tolua_S, arg0, count); CC_SAFE_DELETE_ARRAY(arg0); @@ -1134,7 +1134,7 @@ int lua_cocos2dx_physics_PhysicsShapeEdgePolygon_getPoints(lua_State* tolua_S) if (argc == 0) { int count = cobj->getPointsCount(); - cocos2d::Vec2* arg0 = new cocos2d::Vec2[count]; + cocos2d::Vec2* arg0 = new (std::nothrow) cocos2d::Vec2[count]; cobj->getPoints(arg0); vec2_array_to_luaval(tolua_S, arg0, count); CC_SAFE_DELETE_ARRAY(arg0); @@ -1178,7 +1178,7 @@ int lua_cocos2dx_physics_PhysicsShapeEdgeChain_getPoints(lua_State* tolua_S) if (argc == 0) { int count = cobj->getPointsCount(); - cocos2d::Vec2* arg0 = new cocos2d::Vec2[count]; + cocos2d::Vec2* arg0 = new (std::nothrow) cocos2d::Vec2[count]; cobj->getPoints(arg0); vec2_array_to_luaval(tolua_S, arg0, count); CC_SAFE_DELETE_ARRAY(arg0); diff --git a/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp b/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp index 3673311eae..35dde9d0e4 100644 --- a/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp +++ b/cocos/scripting/lua-bindings/manual/cocostudio/CustomGUIReader.cpp @@ -10,7 +10,7 @@ namespace cocostudio CustomGUIReader* CustomGUIReader::create(std::string &className, int createFunc, int setPropsFunc) { - auto reader = new CustomGUIReader(); + auto reader = new (std::nothrow) CustomGUIReader(); reader->init(className, createFunc, setPropsFunc); return reader; } diff --git a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp index 19a964c980..9339e05939 100644 --- a/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp +++ b/cocos/scripting/lua-bindings/manual/extension/lua_cocos2dx_extension_manual.cpp @@ -602,7 +602,7 @@ static int lua_cocos2dx_TableView_setDelegate(lua_State* L) __Dictionary* userDict = static_cast<__Dictionary*>(self->getUserObject()); if (nullptr == userDict) { - userDict = new __Dictionary(); + userDict = new (std::nothrow) __Dictionary(); if (NULL == userDict) return 0; @@ -739,7 +739,7 @@ static int lua_cocos2dx_TableView_setDataSource(lua_State* L) __Dictionary* userDict = static_cast<__Dictionary*>(self->getUserObject()); if (nullptr == userDict) { - userDict = new __Dictionary(); + userDict = new (std::nothrow) __Dictionary(); if (NULL == userDict) return 0; @@ -807,7 +807,7 @@ static int lua_cocos2dx_TableView_create(lua_State* L) ret->reloadData(); - __Dictionary* userDict = new __Dictionary(); + __Dictionary* userDict = new (std::nothrow) __Dictionary(); userDict->setObject(dataSource, KEY_TABLEVIEW_DATA_SOURCE); ret->setUserObject(userDict); userDict->release(); diff --git a/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp b/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp index 0c77a3f268..7ae79d36e0 100644 --- a/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp +++ b/cocos/scripting/lua-bindings/manual/network/lua_xml_http_request.cpp @@ -70,7 +70,7 @@ void LuaMinXmlHttpRequest::_gotHeader(string header) { // Get Header and Set StatusText // Split String into Tokens - char * cstr = new char [header.length()+1]; + char * cstr = new (std::nothrow) char [header.length()+1]; // check for colon. size_t found_header_field = header.find_first_of(":"); @@ -683,7 +683,7 @@ static int lua_get_XMLHttpRequest_response(lua_State* L) LuaValueArray array; - uint8_t* tmpData = new uint8_t[self->getDataSize()]; + uint8_t* tmpData = new (std::nothrow) uint8_t[self->getDataSize()]; if (nullptr == tmpData) { return 0; diff --git a/cocos/ui/UIEditBox/UIEditBox.cpp b/cocos/ui/UIEditBox/UIEditBox.cpp index d87e6a64f4..9955638d23 100644 --- a/cocos/ui/UIEditBox/UIEditBox.cpp +++ b/cocos/ui/UIEditBox/UIEditBox.cpp @@ -71,7 +71,7 @@ EditBox* EditBox::create(const Size& size, const std::string& normalSprite, TextureResType texType /*= TextureResType::LOCAL*/) { - EditBox* pRet = new EditBox(); + EditBox* pRet = new (std::nothrow) EditBox(); if (pRet != nullptr && pRet->initWithSizeAndBackgroundSprite(size, normalSprite, texType)) { diff --git a/cocos/ui/UILayoutManager.cpp b/cocos/ui/UILayoutManager.cpp index 5d8941384d..a5904ea087 100644 --- a/cocos/ui/UILayoutManager.cpp +++ b/cocos/ui/UILayoutManager.cpp @@ -203,7 +203,7 @@ Widget* RelativeLayoutManager::getRelativeWidget(Widget* widget) return relativeWidget; } -bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout) +bool RelativeLayoutManager::calculateFinalPositionWithRelativeWidget(LayoutProtocol *layout) { Vec2 ap = _widget->getAnchorPoint(); Size cs = _widget->getContentSize(); @@ -426,7 +426,7 @@ bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtoc return true; } -void RelativeLayoutManager::caculateFinalPositionWithRelativeAlign() +void RelativeLayoutManager::calculateFinalPositionWithRelativeAlign() { RelativeLayoutParameter* layoutParameter = dynamic_cast(_widget->getLayoutParameter()); @@ -522,6 +522,16 @@ void RelativeLayoutManager::caculateFinalPositionWithRelativeAlign() } } +bool RelativeLayoutManager::caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout) +{ + return calculateFinalPositionWithRelativeWidget(layout); +} + +void RelativeLayoutManager::caculateFinalPositionWithRelativeAlign() +{ + calculateFinalPositionWithRelativeAlign(); +} + void RelativeLayoutManager::doLayout(LayoutProtocol *layout) { @@ -543,12 +553,12 @@ void RelativeLayoutManager::doLayout(LayoutProtocol *layout) } - bool ret = this->caculateFinalPositionWithRelativeWidget(layout); + bool ret = this->calculateFinalPositionWithRelativeWidget(layout); if (!ret) { continue; } - this->caculateFinalPositionWithRelativeAlign(); + this->calculateFinalPositionWithRelativeAlign(); _widget->setPosition(Vec2(_finalPositionX, _finalPositionY)); diff --git a/cocos/ui/UILayoutManager.h b/cocos/ui/UILayoutManager.h index 2c6a57fac4..8bf404bd72 100644 --- a/cocos/ui/UILayoutManager.h +++ b/cocos/ui/UILayoutManager.h @@ -115,9 +115,15 @@ private: Vector getAllWidgets(LayoutProtocol *layout); Widget* getRelativeWidget(Widget* widget); - bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout); - void caculateFinalPositionWithRelativeAlign(); + bool calculateFinalPositionWithRelativeWidget(LayoutProtocol *layout); + void calculateFinalPositionWithRelativeAlign(); + /** @deprecated Use method calculateFinalPositionWithRelativeWidget() instead */ + CC_DEPRECATED_ATTRIBUTE bool caculateFinalPositionWithRelativeWidget(LayoutProtocol *layout); + + /** @deprecated Use method calculateFinalPositionWithRelativeAlign() instead */ + CC_DEPRECATED_ATTRIBUTE void caculateFinalPositionWithRelativeAlign(); + ssize_t _unlayoutChildCount; Vector _widgetChildren; Widget* _widget; diff --git a/cocos/ui/UIRichText.cpp b/cocos/ui/UIRichText.cpp index eeee8eae38..1dd1e9f603 100644 --- a/cocos/ui/UIRichText.cpp +++ b/cocos/ui/UIRichText.cpp @@ -426,7 +426,7 @@ void RichText::formarRenderers() else { float newContentSizeHeight = 0.0f; - float *maxHeights = new float[_elementRenders.size()]; + float *maxHeights = new (std::nothrow) float[_elementRenders.size()]; for (size_t i=0; i<_elementRenders.size(); i++) { diff --git a/cocos/ui/UIScale9Sprite.cpp b/cocos/ui/UIScale9Sprite.cpp index 91454b8058..22977d6b49 100644 --- a/cocos/ui/UIScale9Sprite.cpp +++ b/cocos/ui/UIScale9Sprite.cpp @@ -84,17 +84,25 @@ namespace ui { bool Scale9Sprite::initWithSpriteFrame(SpriteFrame* spriteFrame, const Rect& capInsets) { - Texture2D* texture = spriteFrame->getTexture(); - CCASSERT(texture != NULL, "CCTexture must be not nil"); - Sprite *sprite = Sprite::createWithSpriteFrame(spriteFrame); - CCASSERT(sprite != NULL, "sprite must be not nil"); - bool pReturn = this->init(sprite, - spriteFrame->getRect(), - spriteFrame->isRotated(), - spriteFrame->getOffset(), - spriteFrame->getOriginalSize(), - capInsets); - return pReturn; + bool ret = false; + do { + Texture2D* texture = spriteFrame->getTexture(); + CCASSERT(texture != NULL, "CCTexture must be not nil"); + if(texture == nullptr) break; + + Sprite *sprite = Sprite::createWithSpriteFrame(spriteFrame); + CCASSERT(sprite != NULL, "sprite must be not nil"); + if(sprite == nullptr) break; + + ret = this->init(sprite, + spriteFrame->getRect(), + spriteFrame->isRotated(), + spriteFrame->getOffset(), + spriteFrame->getOriginalSize(), + capInsets); + } while (false); + + return ret; } bool Scale9Sprite::initWithSpriteFrame(SpriteFrame* spriteFrame) { @@ -105,15 +113,21 @@ namespace ui { bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName, const Rect& capInsets) { - CCASSERT((SpriteFrameCache::getInstance()) != NULL, - "SpriteFrameCache::getInstance() must be non-NULL"); - - SpriteFrame *frame = SpriteFrameCache::getInstance()->getSpriteFrameByName(spriteFrameName); - CCASSERT(frame != NULL, "CCSpriteFrame must be non-NULL"); - - if (NULL == frame) return false; - bool pReturn = this->initWithSpriteFrame(frame, capInsets); - return pReturn; + bool ret = false; + do { + auto spriteFrameCache = SpriteFrameCache::getInstance(); + CCASSERT(spriteFrameCache != nullptr, + "SpriteFrameCache::getInstance() must be non-NULL"); + if(spriteFrameCache == nullptr) break; + + SpriteFrame *frame = spriteFrameCache->getSpriteFrameByName(spriteFrameName); + CCASSERT(frame != nullptr, "CCSpriteFrame must be non-NULL"); + if (frame == nullptr) break; + + ret = initWithSpriteFrame(frame, capInsets); + } while (false); + + return ret; } bool Scale9Sprite::initWithSpriteFrameName(const std::string& spriteFrameName) { @@ -198,16 +212,19 @@ namespace ui { const Rect& rect, const Rect& capInsets) { - Sprite *sprite = nullptr; - sprite = Sprite::create(file); - bool pReturn = this->init(sprite, rect, capInsets); - return pReturn; + CCASSERT(!file.empty(), "file must not be empty string!"); + if(file.empty()) + { + return false; + } + + auto sprite = Sprite::create(file); + return init(sprite, rect, capInsets); } bool Scale9Sprite::initWithFile(const std::string& file, const Rect& rect) { - bool pReturn = this->initWithFile(file, rect, Rect::ZERO); - return pReturn; + return initWithFile(file, rect, Rect::ZERO); } Scale9Sprite* Scale9Sprite::create() @@ -1223,8 +1240,8 @@ namespace ui { CC_SAFE_DELETE_ARRAY(_sliceVertices); CC_SAFE_DELETE_ARRAY(_sliceIndices); - _sliceVertices = new V3F_C4B_T2F[slicedTotalVertexCount]; - _sliceIndices = new unsigned short[slicedTotalIndices]; + _sliceVertices = new (std::nothrow) V3F_C4B_T2F[slicedTotalVertexCount]; + _sliceIndices = new (std::nothrow) unsigned short[slicedTotalIndices]; unsigned short indicesStart = 0; const unsigned short indicesOffset = 6; diff --git a/extensions/GUI/CCScrollView/CCTableView.cpp b/extensions/GUI/CCScrollView/CCTableView.cpp index c27f2c7fb8..bcb1f3c3ea 100644 --- a/extensions/GUI/CCScrollView/CCTableView.cpp +++ b/extensions/GUI/CCScrollView/CCTableView.cpp @@ -55,7 +55,7 @@ bool TableView::initWithViewSize(Size size, Node* container/* = nullptr*/) if (ScrollView::initWithViewSize(size,container)) { CC_SAFE_DELETE(_indices); - _indices = new std::set(); + _indices = new (std::nothrow) std::set(); _vordering = VerticalFillOrder::BOTTOM_UP; this->setDirection(Direction::VERTICAL); diff --git a/extensions/Particle3D/PU/CCPUSlaveBehaviour.cpp b/extensions/Particle3D/PU/CCPUSlaveBehaviour.cpp index e02361149a..5c03b0425a 100644 --- a/extensions/Particle3D/PU/CCPUSlaveBehaviour.cpp +++ b/extensions/Particle3D/PU/CCPUSlaveBehaviour.cpp @@ -57,7 +57,7 @@ PUSlaveBehaviour* PUSlaveBehaviour::clone() PUSlaveBehaviour* PUSlaveBehaviour::create() { - auto pb = new PUSlaveBehaviour(); + auto pb = new (std::nothrow) PUSlaveBehaviour(); pb->autorelease(); return pb; } diff --git a/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp b/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp index 99045c2e06..20c034876c 100644 --- a/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp +++ b/extensions/assets-manager/CCEventListenerAssetsManagerEx.cpp @@ -39,7 +39,7 @@ EventListenerAssetsManagerEx::EventListenerAssetsManagerEx() EventListenerAssetsManagerEx* EventListenerAssetsManagerEx::create(cocos2d::extension::AssetsManagerEx *AssetsManagerEx, const std::function& callback) { - EventListenerAssetsManagerEx* ret = new EventListenerAssetsManagerEx(); + EventListenerAssetsManagerEx* ret = new (std::nothrow) EventListenerAssetsManagerEx(); if (ret && ret->init(AssetsManagerEx, callback)) { ret->autorelease(); @@ -73,7 +73,7 @@ bool EventListenerAssetsManagerEx::init(const AssetsManagerEx *AssetsManagerEx, EventListenerAssetsManagerEx* EventListenerAssetsManagerEx::clone() { - EventListenerAssetsManagerEx* ret = new EventListenerAssetsManagerEx(); + EventListenerAssetsManagerEx* ret = new (std::nothrow) EventListenerAssetsManagerEx(); if (ret && ret->init(_AssetsManagerEx, _onAssetsManagerExEvent)) { ret->autorelease(); diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 990cc6aa85..f29b39db44 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -97,6 +97,7 @@ NewLabelTests::NewLabelTests() ADD_TEST_CASE(LabelToggleTypeTest); ADD_TEST_CASE(LabelSystemFontTest); ADD_TEST_CASE(LabelCharMapFontTest); + ADD_TEST_CASE(LabelIssue13846Test); }; LabelFNTColorAndOpacity::LabelFNTColorAndOpacity() @@ -2759,3 +2760,24 @@ std::string LabelCharMapFontTest::subtitle() const { return ""; } + +LabelIssue13846Test::LabelIssue13846Test() +{ + auto center = VisibleRect::center(); + + auto label = Label::createWithTTF("12345", "fonts/arial.ttf", 26); + label->setPosition(center); + addChild(label); + + label->getLetter(2)->setVisible(false); +} + +std::string LabelIssue13846Test::title() const +{ + return "Test for Issue #13846"; +} + +std::string LabelIssue13846Test::subtitle() const +{ + return "Test hide label's letter,the label should display ‘12 45’ as expected"; +} diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index a803f8d7dd..bed615476c 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -755,4 +755,16 @@ public: virtual std::string title() const override; virtual std::string subtitle() const override; }; + +class LabelIssue13846Test : public AtlasDemoNew +{ +public: + CREATE_FUNC(LabelIssue13846Test); + + LabelIssue13846Test(); + + virtual std::string title() const override; + virtual std::string subtitle() const override; +}; + #endif