mirror of https://github.com/axmolengine/axmol.git
Fixed memory leaks in CCString and CCDictionary, Updated CCFileUtils_ios.mm.Remove inline prefix for some member function of CCString, so that make it compiled successfully on android and ios.
This commit is contained in:
parent
d01f1277af
commit
9ace0d2fdc
|
@ -1 +1 @@
|
||||||
2d9494d763406ba9945e40f011820005d14b92eb
|
ba02d3744870cd69d88ef40bfe303f99d85313a6
|
|
@ -293,7 +293,9 @@ CCDictionary* CCDictionary::dictionaryWithContentsOfFileThreadSafe(const char *p
|
||||||
|
|
||||||
CCDictionary* CCDictionary::dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary* CCDictionary::dictionaryWithContentsOfFile(const char *pFileName)
|
||||||
{
|
{
|
||||||
return dictionaryWithContentsOfFileThreadSafe(pFileName);
|
CCDictionary* pRet = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
||||||
|
pRet->autorelease();
|
||||||
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -180,8 +180,11 @@ CCString* CCString::stringWithContentsOfFile(const char* pszFileName)
|
||||||
{
|
{
|
||||||
unsigned long size = 0;
|
unsigned long size = 0;
|
||||||
unsigned char* pData = 0;
|
unsigned char* pData = 0;
|
||||||
|
CCString* pRet = NULL;
|
||||||
pData = CCFileUtils::getFileData(pszFileName, "rb", &size);
|
pData = CCFileUtils::getFileData(pszFileName, "rb", &size);
|
||||||
return stringWithData(pData, size);
|
pRet = stringWithData(pData, size);
|
||||||
|
CC_SAFE_DELETE_ARRAY(pData);
|
||||||
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -39,48 +39,61 @@ public:
|
||||||
|
|
||||||
virtual ~CCString();
|
virtual ~CCString();
|
||||||
|
|
||||||
/** override assignment operator */
|
/* override assignment operator */
|
||||||
CCString& operator= (const CCString& other);
|
CCString& operator= (const CCString& other);
|
||||||
|
|
||||||
/** init a string with format, it's similar with the c function 'sprintf' */
|
/** init a string with format, it's similar with the c function 'sprintf' */
|
||||||
bool initWithFormat(const char* format, ...);
|
bool initWithFormat(const char* format, ...);
|
||||||
|
|
||||||
/** convert to int value */
|
/** convert to int value */
|
||||||
inline int intValue() const;
|
int intValue() const;
|
||||||
|
|
||||||
/** convert to unsigned int value */
|
/** convert to unsigned int value */
|
||||||
inline unsigned int uintValue() const;
|
unsigned int uintValue() const;
|
||||||
|
|
||||||
/** convert to float value */
|
/** convert to float value */
|
||||||
inline float floatValue() const;
|
float floatValue() const;
|
||||||
|
|
||||||
/** convert to double value */
|
/** convert to double value */
|
||||||
inline double doubleValue() const;
|
double doubleValue() const;
|
||||||
|
|
||||||
/** convert to bool value */
|
/** convert to bool value */
|
||||||
inline bool boolValue() const;
|
bool boolValue() const;
|
||||||
|
|
||||||
/** get the C string */
|
/** get the C string */
|
||||||
inline const char* getCString() const;
|
const char* getCString() const;
|
||||||
|
|
||||||
/** get the length of string */
|
/** get the length of string */
|
||||||
inline unsigned int length() const;
|
unsigned int length() const;
|
||||||
|
|
||||||
/** override functions */
|
/* override functions */
|
||||||
virtual CCObject* copyWithZone(CCZone* pZone);
|
virtual CCObject* copyWithZone(CCZone* pZone);
|
||||||
virtual bool isEqual(const CCObject* pObject);
|
virtual bool isEqual(const CCObject* pObject);
|
||||||
|
|
||||||
/** static funcitons */
|
/* static funcitons */
|
||||||
/** create a string with c string */
|
/** create a string with c string
|
||||||
|
* @return A CCString pointer which is an autorelease object pointer,
|
||||||
|
* it means that you needn't do a release operation unless you retain it.
|
||||||
|
*/
|
||||||
static CCString* stringWithCString(const char* pStr);
|
static CCString* stringWithCString(const char* pStr);
|
||||||
|
|
||||||
/** create a string with format, it's similar with the c function 'sprintf' */
|
/** create a string with format, it's similar with the c function 'sprintf', the default buffer size is (1024*100) bytes,
|
||||||
|
* if you want to change it, you should modify the kMaxStringLen macro in CCString.cpp file.
|
||||||
|
* @return A CCString pointer which is an autorelease object pointer,
|
||||||
|
* it means that you needn't do a release operation unless you retain it.
|
||||||
|
*/
|
||||||
static CCString* stringWithFormat(const char* format, ...);
|
static CCString* stringWithFormat(const char* format, ...);
|
||||||
|
|
||||||
/** create a string with binary data */
|
/** create a string with binary data
|
||||||
|
* @return A CCString pointer which is an autorelease object pointer,
|
||||||
|
* it means that you needn't do a release operation unless you retain it.
|
||||||
|
*/
|
||||||
static CCString* stringWithData(unsigned char* pData, unsigned long nLen);
|
static CCString* stringWithData(unsigned char* pData, unsigned long nLen);
|
||||||
|
|
||||||
/** create a string with a file */
|
/** create a string with a file,
|
||||||
|
* @return A CCString pointer which is an autorelease object pointer,
|
||||||
|
* it means that you needn't do a release operation unless you retain it.
|
||||||
|
*/
|
||||||
static CCString* stringWithContentsOfFile(const char* pszFileName);
|
static CCString* stringWithContentsOfFile(const char* pszFileName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -34,6 +34,7 @@ THE SOFTWARE.
|
||||||
#include "CCFileUtils.h"
|
#include "CCFileUtils.h"
|
||||||
#include "CCDirector.h"
|
#include "CCDirector.h"
|
||||||
#include "CCSAXParser.h"
|
#include "CCSAXParser.h"
|
||||||
|
#include "CCDictionary.h"
|
||||||
#include "support/zip_support/unzip.h"
|
#include "support/zip_support/unzip.h"
|
||||||
|
|
||||||
#define MAX_PATH 260
|
#define MAX_PATH 260
|
||||||
|
@ -415,17 +416,9 @@ namespace cocos2d {
|
||||||
return pRet->m_sString.c_str();
|
return pRet->m_sString.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
CCDictionary *CCFileUtils::dictionaryWithContentsOfFile(const char *pFileName)
|
CCDictionary* ccFileUtils_dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
||||||
{
|
{
|
||||||
CCDictionary *ret = dictionaryWithContentsOfFileThreadSafe(pFileName);
|
const char* pszFullPath = CCFileUtils::fullPathFromRelativePath(pFileName);
|
||||||
ret->autorelease();
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
CCDictionary *CCFileUtils::dictionaryWithContentsOfFileThreadSafe(const char *pFileName)
|
|
||||||
{
|
|
||||||
const char* pszFullPath = fullPathFromRelativePath(pFileName);
|
|
||||||
NSString* pPath = [NSString stringWithUTF8String:pszFullPath];
|
NSString* pPath = [NSString stringWithUTF8String:pszFullPath];
|
||||||
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
|
NSDictionary* pDict = [NSDictionary dictionaryWithContentsOfFile:pPath];
|
||||||
|
|
||||||
|
@ -434,7 +427,7 @@ namespace cocos2d {
|
||||||
id value = [pDict objectForKey:key];
|
id value = [pDict objectForKey:key];
|
||||||
static_addValueToCCDict(key, value, pRet);
|
static_addValueToCCDict(key, value, pRet);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pRet;
|
return pRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
80c6fdfc6a77f7b0475ad0c3edbc6097d604d506
|
b9cda1260ba870cf512eba65876376a4b0f6c7df
|
|
@ -187,6 +187,9 @@ void TestController::menuCallback(CCObject * pSender)
|
||||||
void TestController::closeCallback(CCObject * pSender)
|
void TestController::closeCallback(CCObject * pSender)
|
||||||
{
|
{
|
||||||
CCDirector::sharedDirector()->end();
|
CCDirector::sharedDirector()->end();
|
||||||
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
|
exit(0);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
|
||||||
|
|
Loading…
Reference in New Issue