Skip to content

Commit 3a985fb

Browse files
author
natural-law
committed
[android]fixed cocos2d#356,modify the parameter type form ccxScopedPtr<std::string> to std::string *.
1 parent 4a3ceaf commit 3a985fb

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

cocos2dx/include/CCLabelTTF.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ namespace cocos2d{
3737
class CC_DLL CCLabelTTF : public CCSprite, public CCLabelProtocol
3838
{
3939
public:
40-
CCLabelTTF() {}
41-
virtual ~CCLabelTTF(){}
40+
CCLabelTTF();
41+
virtual ~CCLabelTTF();
4242
char * description();
4343
/** creates a CCLabelTTF from a fontname, alignment, dimension and font size */
4444
static CCLabelTTF * labelWithString(const char *label, CCSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize);
@@ -59,9 +59,9 @@ namespace cocos2d{
5959
protected:
6060
CCSize m_tDimensions;
6161
UITextAlignment m_eAlignment;
62-
ccxScopedPtr<std::string> m_pFontName;
62+
std::string * m_pFontName;
6363
float m_fFontSize;
64-
ccxScopedPtr<std::string> m_pString;
64+
std::string * m_pString;
6565
};
6666

6767
} //namespace cocos2d

cocos2dx/label_nodes/CCLabelTTF.cpp

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ namespace cocos2d{
2727
//
2828
//CCLabelTTF
2929
//
30+
CCLabelTTF::CCLabelTTF()
31+
: m_pFontName(NULL)
32+
, m_pString(NULL)
33+
{
34+
}
35+
36+
CCLabelTTF::~CCLabelTTF()
37+
{
38+
if (m_pFontName)
39+
{
40+
delete m_pFontName;
41+
m_pFontName = NULL;
42+
}
43+
44+
if (m_pString)
45+
{
46+
delete m_pString;
47+
m_pString = NULL;
48+
}
49+
50+
}
51+
3052
CCLabelTTF * CCLabelTTF::labelWithString(const char *label, CCSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
3153
{
3254
CCLabelTTF *pRet = new CCLabelTTF();
@@ -57,7 +79,14 @@ namespace cocos2d{
5779
{
5880
m_tDimensions = CCSizeMake( dimensions.width * CC_CONTENT_SCALE_FACTOR(), dimensions.height * CC_CONTENT_SCALE_FACTOR() );
5981
m_eAlignment = alignment;
60-
m_pFontName.reset(new std::string(fontName));
82+
83+
if (m_pFontName)
84+
{
85+
delete m_pFontName;
86+
m_pFontName = NULL;
87+
}
88+
m_pFontName = new std::string(fontName);
89+
6190
m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR();
6291
this->setString(label);
6392
return true;
@@ -70,7 +99,14 @@ namespace cocos2d{
7099
if (CCSprite::init())
71100
{
72101
m_tDimensions = CCSizeZero;
73-
m_pFontName.reset(new std::string(fontName));
102+
103+
if (m_pFontName)
104+
{
105+
delete m_pFontName;
106+
m_pFontName = NULL;
107+
}
108+
m_pFontName = new std::string(fontName);
109+
74110
m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR();
75111
this->setString(label);
76112
return true;
@@ -79,7 +115,12 @@ namespace cocos2d{
79115
}
80116
void CCLabelTTF::setString(const char *label)
81117
{
82-
m_pString.reset(new std::string(label));
118+
if (m_pString)
119+
{
120+
delete m_pString;
121+
m_pString = NULL;
122+
}
123+
m_pString = new std::string(label);
83124

84125
CCTexture2D *texture;
85126
if( CCSize::CCSizeEqualToSize( m_tDimensions, CCSizeZero ) )

0 commit comments

Comments
 (0)