Merge pull request #5010 from boyu0/fix_texture2dtest_crash_bug

closed #3638: Fix Image crashes when load tga file.
This commit is contained in:
James Chen 2014-01-09 00:40:09 -08:00
commit 3bb1fae660
1 changed files with 4 additions and 6 deletions

View File

@ -376,7 +376,7 @@ namespace
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
Image::Image() Image::Image()
: _data(0) : _data(nullptr)
, _dataLen(0) , _dataLen(0)
, _width(0) , _width(0)
, _height(0) , _height(0)
@ -391,10 +391,7 @@ Image::Image()
Image::~Image() Image::~Image()
{ {
if (_data != nullptr) CC_SAFE_FREE(_data);
{
free(_data);
}
} }
bool Image::initWithImageFile(const std::string& path) bool Image::initWithImageFile(const std::string& path)
@ -1539,7 +1536,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
}while(false); }while(false);
if (!ret) if (ret)
{ {
const unsigned char tgaSuffix[] = ".tga"; const unsigned char tgaSuffix[] = ".tga";
for(int i = 0; i < 4; ++i) for(int i = 0; i < 4; ++i)
@ -1556,6 +1553,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData)
if (tgaData->imageData != nullptr) if (tgaData->imageData != nullptr)
{ {
free(tgaData->imageData); free(tgaData->imageData);
_data = nullptr;
} }
} }