Merge pull request #42 from WenhaiLin/master

Fixed memory leak and warns
This commit is contained in:
Wenhai Lin
2016-04-21 23:51:53 +08:00
12 changed files with 33 additions and 32 deletions
-2
View File
@@ -857,7 +857,6 @@ bool Label::updateQuads()
batchNode->getTextureAtlas()->removeAllQuads();
}
bool letterClamp = false;
for (int ctr = 0; ctr < _lengthOfString; ++ctr)
{
if (_lettersInfo[ctr].valid)
@@ -893,7 +892,6 @@ bool Label::updateQuads()
_reusedRect.size.width = 0;
}else if(_overflow == Overflow::SHRINK){
if (_contentSize.width > letterDef.width) {
letterClamp = true;
ret = false;
break;
}else{
+5 -5
View File
@@ -383,7 +383,8 @@ void MenuItemSprite::setNormalImage(Node* image)
if (image)
{
addChild(image);
image->setAnchorPoint(Vec2(0, 0));
image->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
setContentSize(image->getContentSize());
}
if (_normalImage)
@@ -392,7 +393,6 @@ void MenuItemSprite::setNormalImage(Node* image)
}
_normalImage = image;
this->setContentSize(_normalImage->getContentSize());
this->updateImagesVisibility();
}
}
@@ -536,7 +536,7 @@ void MenuItemSprite::updateImagesVisibility()
{
if (_enabled)
{
if (_normalImage) _normalImage->setVisible(true);
if (_normalImage) _normalImage->setVisible(true);
if (_selectedImage) _selectedImage->setVisible(false);
if (_disabledImage) _disabledImage->setVisible(false);
}
@@ -544,13 +544,13 @@ void MenuItemSprite::updateImagesVisibility()
{
if (_disabledImage)
{
if (_normalImage) _normalImage->setVisible(false);
if (_normalImage) _normalImage->setVisible(false);
if (_selectedImage) _selectedImage->setVisible(false);
if (_disabledImage) _disabledImage->setVisible(true);
}
else
{
if (_normalImage) _normalImage->setVisible(true);
if (_normalImage) _normalImage->setVisible(true);
if (_selectedImage) _selectedImage->setVisible(false);
if (_disabledImage) _disabledImage->setVisible(false);
}
-1
View File
@@ -767,7 +767,6 @@ void EventDispatcher::dispatchEventToListeners(EventListenerVector* listeners, c
if (l->isEnabled() && !l->isPaused() && l->isRegistered() && onEvent(l))
{
shouldStopPropagation = true;
break;
}
}
+1 -1
View File
@@ -140,7 +140,7 @@ static bool isVariable(const char* str, char* outName, size_t outSize)
size_t size = len - 3;
if (size > (outSize - 1))
size = outSize - 1;
strncpy(outName, str + 2, len - 3);
strncpy(outName, str + 2, size);
outName[len - 3] = 0;
return true;
}
@@ -655,7 +655,7 @@ Node * CCBReader::readNodeGraph(Node * pParent)
if(!assigned && this->_CCBMemberVariableAssigner != nullptr)
{
assigned = this->_CCBMemberVariableAssigner->onAssignCCBMemberVariable(target, memberVarAssignmentName.c_str(), node);
_CCBMemberVariableAssigner->onAssignCCBMemberVariable(target, memberVarAssignmentName.c_str(), node);
}
}
}
@@ -696,7 +696,7 @@ Node * CCBReader::readNodeGraph(Node * pParent)
if(!customAssigned && this->_CCBMemberVariableAssigner != nullptr)
{
customAssigned = this->_CCBMemberVariableAssigner->onAssignCCBCustomProperty(target, iter->first.c_str(), iter->second);
_CCBMemberVariableAssigner->onAssignCCBCustomProperty(target, iter->first.c_str(), iter->second);
}
}
}
@@ -229,7 +229,7 @@ ActionMoveFrame::~ActionMoveFrame()
{
}
void ActionMoveFrame::setPosition(Vec2 pos)
void ActionMoveFrame::setPosition(const Vec2& pos)
{
_position = pos;
}
@@ -357,7 +357,7 @@ ActionTintFrame::~ActionTintFrame()
}
void ActionTintFrame::setColor(Color3B ccolor)
void ActionTintFrame::setColor(const Color3B& ccolor)
{
_color = ccolor;
}
@@ -230,7 +230,7 @@ public:
*
* @param the move action position.
*/
void setPosition(cocos2d::Vec2 pos);
void setPosition(const cocos2d::Vec2& pos);
/**
* Gets the move action position.
@@ -429,7 +429,7 @@ public:
*
* @param ccolor the tint action color
*/
void setColor(cocos2d::Color3B ccolor);
void setColor(const cocos2d::Color3B& ccolor);
/**
* Gets the tint action color.
@@ -172,16 +172,16 @@ CocoLoader::~CocoLoader()
}
bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
bool CocoLoader::ReadCocoBinBuff(char* pBinBuff)
{
if(m_pMemoryBuff)return true;
char* pTempBuff = pBinBuff;
m_pFileHeader = (stCocoFileHeader*)pTempBuff;
pTempBuff += sizeof(stCocoFileHeader);
char* pStartAddr = m_pMemoryBuff = pTempBuff;
char* pStartAddr = m_pMemoryBuff = pTempBuff;
char* pDestBuff = new char[m_pFileHeader->m_nDataSize];
char* pDestBuff = new char[m_pFileHeader->m_nDataSize];
if (m_pFileHeader->m_nCompressSize > 0)
{
uLongf dwSrcSize = m_pFileHeader->m_nCompressSize;
@@ -663,7 +663,10 @@ bool jsval_to_array_of_cpvect( JSContext *cx, jsval vp, cpVect**verts, int *numV
double value = 0;
ok = JS::ToNumber(cx, valarg, &value);
JSB_PRECONDITION( ok, "Error converting value to nsobject");
if (!ok) {
free(array);
}
JSB_PRECONDITION(ok, "Error converting value to nsobject");
if(i%2==0)
array[i/2].x = value;
@@ -917,6 +917,8 @@ bool jsval_to_ccarray_of_CCPoint(JSContext* cx, JS::HandleValue v, Point **point
JS_GetElement(cx, jsobj, i, &valarg);
ok = jsval_to_ccpoint(cx, valarg, &array[i]);
if(!ok)
delete [] array;
JSB_PRECONDITION3(ok, cx, false, "Error processing arguments");
}
@@ -292,12 +292,8 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j
JS::RootedObject proto(cx, js_cocos2dx_websocket_prototype);
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 (std::nothrow) WebSocket();
auto delegate = new (std::nothrow) JSB_WebSocketDelegate(cx);
delegate->setJSDelegate(obj);
WebSocket* cobj = nullptr;
if (argc == 2)
{
std::vector<std::string> protocols;
@@ -333,14 +329,20 @@ bool js_cocos2dx_extension_WebSocket_constructor(JSContext *cx, uint32_t argc, j
protocols.push_back(protocol);
}
}
cobj = new (std::nothrow) WebSocket();
auto delegate = new (std::nothrow) JSB_WebSocketDelegate(cx);
delegate->setJSDelegate(obj);
cobj->init(*delegate, url, &protocols);
}
else
{
cobj = new (std::nothrow) WebSocket();
auto delegate = new (std::nothrow) JSB_WebSocketDelegate(cx);
delegate->setJSDelegate(obj);
cobj->init(*delegate, url);
}
JS_DefineProperty(cx, obj, "URL", args.get(0), JSPROP_ENUMERATE | JSPROP_PERMANENT | JSPROP_READONLY);
//protocol not support yet (always return "")
+4 -7
View File
@@ -1062,27 +1062,24 @@ namespace ui {
bottomHeight = originalSize.height - (capInsets.origin.y + centerHeight) - offsets.w;
}
if(leftWidth<0)
if(leftWidth < 0)
{
centerWidth += leftWidth;
leftWidth = 0;
}
if(rightWidth<0)
if(rightWidth < 0)
{
centerWidth += rightWidth;
rightWidth = 0;
}
if(topHeight<0)
if(topHeight < 0)
{
centerHeight += topHeight;
topHeight = 0;
}
if(bottomHeight<0)
if(bottomHeight < 0)
{
centerHeight += bottomHeight;
bottomHeight = 0;
}
auto textureRect = CC_RECT_POINTS_TO_PIXELS(_spriteRect);