be safe to handle operator= (#18850)

* 等号赋值函数,先判断this是否不等于other再做赋值

1、CCData那个会闪退
2、CCGLProgramState那个会造成_value.tex.texture泄漏

* replace TAB to  4 SPACE
This commit is contained in:
panzhihao 2018-05-25 09:58:11 +08:00 committed by leda
parent a44e208975
commit cc145cb852
2 changed files with 20 additions and 11 deletions

View File

@ -62,15 +62,21 @@ Data::~Data()
Data& Data::operator= (const Data& other)
{
CCLOGINFO("In the copy assignment of Data.");
copy(other._bytes, other._size);
if (this != &other)
{
CCLOGINFO("In the copy assignment of Data.");
copy(other._bytes, other._size);
}
return *this;
}
Data& Data::operator= (Data&& other)
{
CCLOGINFO("In the move assignment of Data.");
move(other);
if (this != &other)
{
CCLOGINFO("In the move assignment of Data.");
move(other);
}
return *this;
}

View File

@ -273,14 +273,17 @@ void UniformValue::setMat4(const Mat4& value)
UniformValue& UniformValue::operator=(const UniformValue& o)
{
_uniform = o._uniform;
_glprogram = o._glprogram;
_type = o._type;
_value = o._value;
if (_uniform->type == GL_SAMPLER_2D)
if (this != &o)
{
CC_SAFE_RETAIN(_value.tex.texture);
_uniform = o._uniform;
_glprogram = o._glprogram;
_type = o._type;
_value = o._value;
if (_uniform->type == GL_SAMPLER_2D)
{
CC_SAFE_RETAIN(_value.tex.texture);
}
}
return *this;
}