Merge pull request #4571 from dumganhar/user-default-fix

closed #3457: Fix of UserDefault. Infinite loop in UserDefault's destructor on iOS. The destructor of UserDefault is private now.
This commit is contained in:
minggo 2013-12-19 22:16:02 -08:00
commit d3e7ccd872
4 changed files with 8 additions and 34 deletions

View File

@ -140,23 +140,16 @@ static void setValueForKey(const char* pKey, const char* pValue)
* implements of UserDefault * implements of UserDefault
*/ */
UserDefault* UserDefault::_userDefault = 0; UserDefault* UserDefault::_userDefault = nullptr;
string UserDefault::_filePath = string(""); string UserDefault::_filePath = string("");
bool UserDefault::_isFilePathInitialized = false; bool UserDefault::_isFilePathInitialized = false;
/**
* If the user invoke delete UserDefault::getInstance(), should set _userDefault
* to null to avoid error when he invoke UserDefault::getInstance() later.
*/
UserDefault::~UserDefault() UserDefault::~UserDefault()
{ {
CC_SAFE_DELETE(_userDefault);
_userDefault = nullptr;
} }
UserDefault::UserDefault() UserDefault::UserDefault()
{ {
_userDefault = nullptr;
} }
bool UserDefault::getBoolForKey(const char* pKey) bool UserDefault::getBoolForKey(const char* pKey)
@ -433,7 +426,7 @@ UserDefault* UserDefault::getInstance()
void UserDefault::destroyInstance() void UserDefault::destroyInstance()
{ {
_userDefault = nullptr; CC_SAFE_DELETE(_userDefault);
} }
// XXX: deprecated // XXX: deprecated

View File

@ -46,12 +46,6 @@ NS_CC_BEGIN
class CC_DLL UserDefault class CC_DLL UserDefault
{ {
public: public:
/**
* @js NA
* @lua NA
*/
~UserDefault();
// get value methods // get value methods
/** /**
@ -186,6 +180,8 @@ public:
private: private:
UserDefault(); UserDefault();
~UserDefault();
static bool createXMLFile(); static bool createXMLFile();
static void initXMLFilePath(); static void initXMLFilePath();

View File

@ -48,7 +48,7 @@ NS_CC_BEGIN
* implements of UserDefault * implements of UserDefault
*/ */
UserDefault* UserDefault::_userDefault = 0; UserDefault* UserDefault::_userDefault = nullptr;
string UserDefault::_filePath = string(""); string UserDefault::_filePath = string("");
bool UserDefault::_isFilePathInitialized = false; bool UserDefault::_isFilePathInitialized = false;
@ -134,19 +134,12 @@ static void deleteNodeByKey(const char *pKey)
} }
#endif #endif
/**
* If the user invoke delete UserDefault::getInstance(), should set _userDefault
* to null to avoid error when he invoke UserDefault::getInstance() later.
*/
UserDefault::~UserDefault() UserDefault::~UserDefault()
{ {
CC_SAFE_DELETE(_userDefault);
_userDefault = nullptr;
} }
UserDefault::UserDefault() UserDefault::UserDefault()
{ {
_userDefault = nullptr;
} }
bool UserDefault::getBoolForKey(const char* pKey) bool UserDefault::getBoolForKey(const char* pKey)
@ -503,8 +496,7 @@ UserDefault* UserDefault::getInstance()
void UserDefault::destroyInstance() void UserDefault::destroyInstance()
{ {
delete _userDefault; CC_SAFE_DELETE(_userDefault);
_userDefault = nullptr;
} }
// XXX: deprecated // XXX: deprecated

View File

@ -49,7 +49,7 @@ NS_CC_BEGIN
* implements of UserDefault * implements of UserDefault
*/ */
UserDefault* UserDefault::_userDefault = 0; UserDefault* UserDefault::_userDefault = nullptr;
string UserDefault::_filePath = string(""); string UserDefault::_filePath = string("");
bool UserDefault::_isFilePathInitialized = false; bool UserDefault::_isFilePathInitialized = false;
@ -135,19 +135,12 @@ static void deleteNodeByKey(const char *pKey)
} }
#endif #endif
/**
* If the user invoke delete UserDefault::getInstance(), should set _userDefault
* to null to avoid error when he invoke UserDefault::getInstance() later.
*/
UserDefault::~UserDefault() UserDefault::~UserDefault()
{ {
CC_SAFE_DELETE(_userDefault);
_userDefault = nullptr;
} }
UserDefault::UserDefault() UserDefault::UserDefault()
{ {
_userDefault = nullptr;
} }
// XXX: deprecated // XXX: deprecated
@ -158,7 +151,7 @@ void UserDefault::purgeSharedUserDefault()
void UserDefault::destroyInstance() void UserDefault::destroyInstance()
{ {
_userDefault = nullptr; CC_SAFE_DELETE(_userDefault);
} }
bool UserDefault::getBoolForKey(const char* pKey) bool UserDefault::getBoolForKey(const char* pKey)