@@ -27,6 +27,28 @@ namespace cocos2d{
27
27
//
28
28
// CCLabelTTF
29
29
//
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
+
30
52
CCLabelTTF * CCLabelTTF::labelWithString (const char *label, CCSize dimensions, UITextAlignment alignment, const char *fontName, float fontSize)
31
53
{
32
54
CCLabelTTF *pRet = new CCLabelTTF ();
@@ -57,7 +79,14 @@ namespace cocos2d{
57
79
{
58
80
m_tDimensions = CCSizeMake ( dimensions.width * CC_CONTENT_SCALE_FACTOR (), dimensions.height * CC_CONTENT_SCALE_FACTOR () );
59
81
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
+
61
90
m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR ();
62
91
this ->setString (label);
63
92
return true ;
@@ -70,7 +99,14 @@ namespace cocos2d{
70
99
if (CCSprite::init ())
71
100
{
72
101
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
+
74
110
m_fFontSize = fontSize * CC_CONTENT_SCALE_FACTOR ();
75
111
this ->setString (label);
76
112
return true ;
@@ -79,7 +115,12 @@ namespace cocos2d{
79
115
}
80
116
void CCLabelTTF::setString (const char *label)
81
117
{
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);
83
124
84
125
CCTexture2D *texture;
85
126
if ( CCSize::CCSizeEqualToSize ( m_tDimensions, CCSizeZero ) )
0 commit comments