From e063755596531755527f214a5d9c5a0ea5d14fa3 Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 9 Jan 2014 15:26:05 +0800 Subject: [PATCH 1/2] fix Image crashes in mac when load tag file --- cocos/2d/platform/CCImageCommon_cpp.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index 6c5c7a2d96..fa331d313f 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -391,10 +391,7 @@ Image::Image() Image::~Image() { - if (_data != nullptr) - { - free(_data); - } + CC_SAFE_FREE(_data); } bool Image::initWithImageFile(const std::string& path) @@ -1539,7 +1536,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData) }while(false); - if (!ret) + if (ret) { const unsigned char tgaSuffix[] = ".tga"; for(int i = 0; i < 4; ++i) @@ -1556,6 +1553,7 @@ bool Image::initWithTGAData(tImageTGA* tgaData) if (tgaData->imageData != nullptr) { free(tgaData->imageData); + _data = nullptr; } } From e34ef0d38fb67fd38cae826a2fae75cd35dc963e Mon Sep 17 00:00:00 2001 From: boyu0 Date: Thu, 9 Jan 2014 16:33:31 +0800 Subject: [PATCH 2/2] change initialization _data from 0 to nullptr. --- cocos/2d/platform/CCImageCommon_cpp.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cocos/2d/platform/CCImageCommon_cpp.h b/cocos/2d/platform/CCImageCommon_cpp.h index fa331d313f..40eeca0ae7 100644 --- a/cocos/2d/platform/CCImageCommon_cpp.h +++ b/cocos/2d/platform/CCImageCommon_cpp.h @@ -376,7 +376,7 @@ namespace ////////////////////////////////////////////////////////////////////////// Image::Image() -: _data(0) +: _data(nullptr) , _dataLen(0) , _width(0) , _height(0)