From 61134426a8d952ade6699d1844b49c373d88fdcf Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 9 Apr 2014 20:41:09 +0800 Subject: [PATCH] Some fixes detected by xcode analyze --- cocos/2d/CCFontAtlas.cpp | 4 ++-- cocos/2d/CCFontFreeType.cpp | 2 +- cocos/2d/CCLabel.cpp | 20 +++++++++++--------- cocos/2d/CCNodeGrid.cpp | 2 +- cocos/2d/CCTextureAtlas.cpp | 3 ++- cocos/2d/platform/CCGLViewProtocol.cpp | 1 - cocos/2d/platform/CCImage.cpp | 2 +- cocos/ui/UILayout.cpp | 10 +++------- 8 files changed, 21 insertions(+), 23 deletions(-) diff --git a/cocos/2d/CCFontAtlas.cpp b/cocos/2d/CCFontAtlas.cpp index 3ef99242f0..fff6d1ae94 100644 --- a/cocos/2d/CCFontAtlas.cpp +++ b/cocos/2d/CCFontAtlas.cpp @@ -237,7 +237,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) bool existNewLetter = false; int bottomHeight = _commonLineHeight - _fontAscender; - float startX = _currentPageOrigX; + float startY = _currentPageOrigY; for (int i = 0; i < length; ++i) @@ -268,7 +268,7 @@ bool FontAtlas::prepareLetterDefinitions(unsigned short *utf16String) auto data = _currentPageData + CacheTextureWidth * (int)startY; _atlasTextures[_currentPage]->updateWithData(data, 0, startY, CacheTextureWidth, CacheTextureHeight - startY); - startX = 0.0f; + startY = 0.0f; _currentPageOrigY = 0; diff --git a/cocos/2d/CCFontFreeType.cpp b/cocos/2d/CCFontFreeType.cpp index a7611e0d0f..c9fe2d8c41 100644 --- a/cocos/2d/CCFontFreeType.cpp +++ b/cocos/2d/CCFontFreeType.cpp @@ -497,7 +497,7 @@ void FontFreeType::renderCharAt(unsigned char *dest,int posX, int posY, unsigned { long bitmap_y = y * bitmapWidth; - for (int x = 0; x < bitmapWidth; ++x) + for (long x = 0; x < bitmapWidth; ++x) { /* Dual channel 16-bit output (more complicated, but good precision and range) */ /*int index = (iX + ( iY * destSize )) * 3; diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index 79ad885cdd..8a7325fc47 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -1081,15 +1081,17 @@ void Label::drawTextSprite(Renderer *renderer, bool parentTransformUpdated) if (_shadowEnabled && _shadowNode == nullptr) { _shadowNode = Sprite::createWithTexture(_textSprite->getTexture()); - if (_shadowNode && _blendFuncDirty) + if (_shadowNode) { - _shadowNode->setBlendFunc(_blendFunc); + if (_blendFuncDirty) + _shadowNode->setBlendFunc(_blendFunc); + + _shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); + _shadowNode->setColor(_shadowColor); + _shadowNode->setOpacity(_shadowOpacity * _displayedOpacity); + _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); + Node::addChild(_shadowNode,0,Node::INVALID_TAG); } - _shadowNode->setAnchorPoint(Point::ANCHOR_BOTTOM_LEFT); - _shadowNode->setColor(_shadowColor); - _shadowNode->setOpacity(_shadowOpacity * _displayedOpacity); - _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); - Node::addChild(_shadowNode,0,Node::INVALID_TAG); } if (_shadowNode) { @@ -1236,7 +1238,7 @@ void Label::computeStringNumLines() { int quantityOfLines = 1; - unsigned int stringLen = _currentUTF16String ? cc_wcslen(_currentUTF16String) : -1; + int stringLen = _currentUTF16String ? cc_wcslen(_currentUTF16String) : -1; if (stringLen < 1) { _currNumLines = stringLen; @@ -1244,7 +1246,7 @@ void Label::computeStringNumLines() } // count number of lines - for (unsigned int i = 0; i < stringLen - 1; ++i) + for (int i = 0; i < stringLen - 1; ++i) { if (_currentUTF16String[i] == '\n') { diff --git a/cocos/2d/CCNodeGrid.cpp b/cocos/2d/CCNodeGrid.cpp index 66585a3c61..9678a39012 100644 --- a/cocos/2d/CCNodeGrid.cpp +++ b/cocos/2d/CCNodeGrid.cpp @@ -105,7 +105,7 @@ void NodeGrid::visit(Renderer *renderer, const kmMat4 &parentTransform, bool par kmGLPushMatrix(); kmGLLoadMatrix(&_modelViewTransform); - Director::Projection beforeProjectionType; + Director::Projection beforeProjectionType = Director::Projection::DEFAULT; if(_nodeGrid && _nodeGrid->isActive()) { beforeProjectionType = Director::getInstance()->getProjection(); diff --git a/cocos/2d/CCTextureAtlas.cpp b/cocos/2d/CCTextureAtlas.cpp index a71ecf19f6..208cc24329 100644 --- a/cocos/2d/CCTextureAtlas.cpp +++ b/cocos/2d/CCTextureAtlas.cpp @@ -483,6 +483,7 @@ bool TextureAtlas::resizeCapacity(ssize_t newCapacity) { memset(tmpQuads+oldCapactiy, 0, (_capacity - oldCapactiy)*sizeof(_quads[0]) ); } + _quads = nullptr; } if (_indices == nullptr) @@ -492,7 +493,6 @@ bool TextureAtlas::resizeCapacity(ssize_t newCapacity) { memset( tmpIndices, 0, _capacity * 6 * sizeof(_indices[0]) ); } - } else { @@ -501,6 +501,7 @@ bool TextureAtlas::resizeCapacity(ssize_t newCapacity) { memset( tmpIndices+oldCapactiy, 0, (_capacity-oldCapactiy) * 6 * sizeof(_indices[0]) ); } + _indices = nullptr; } if( ! ( tmpQuads && tmpIndices) ) { diff --git a/cocos/2d/platform/CCGLViewProtocol.cpp b/cocos/2d/platform/CCGLViewProtocol.cpp index a04f67a020..2a2ac08506 100644 --- a/cocos/2d/platform/CCGLViewProtocol.cpp +++ b/cocos/2d/platform/CCGLViewProtocol.cpp @@ -250,7 +250,6 @@ void GLViewProtocol::handleTouchesBegin(int num, intptr_t ids[], float xs[], flo y = ys[i]; auto iter = g_touchIdReorderMap.find(id); - unusedIndex = 0; // it is a new touch if (iter == g_touchIdReorderMap.end()) diff --git a/cocos/2d/platform/CCImage.cpp b/cocos/2d/platform/CCImage.cpp index 324c525730..a502a5b815 100644 --- a/cocos/2d/platform/CCImage.cpp +++ b/cocos/2d/platform/CCImage.cpp @@ -1552,7 +1552,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData) } else { - if (tgaData->imageData != nullptr) + if (tgaData && tgaData->imageData != nullptr) { free(tgaData->imageData); _data = nullptr; diff --git a/cocos/ui/UILayout.cpp b/cocos/ui/UILayout.cpp index 27ce84dfa4..7399653ad4 100644 --- a/cocos/ui/UILayout.cpp +++ b/cocos/ui/UILayout.cpp @@ -1003,7 +1003,7 @@ const Rect& Layout::getClippingRect() float scissorHeight = _size.height*t.d; Rect parentClippingRect; Layout* parent = this; - bool firstClippingParentFounded = false; + while (parent) { parent = dynamic_cast(parent->getParent()); @@ -1011,12 +1011,8 @@ const Rect& Layout::getClippingRect() { if (parent->isClippingEnabled()) { - if (!firstClippingParentFounded) - { - _clippingParent = parent; - firstClippingParentFounded = true; - break; - } + _clippingParent = parent; + break; } } }