diff --git a/cocos2dx/CCDirector.cpp b/cocos2dx/CCDirector.cpp index fcf2c435b5..ddf3387ef6 100644 --- a/cocos2dx/CCDirector.cpp +++ b/cocos2dx/CCDirector.cpp @@ -46,6 +46,7 @@ THE SOFTWARE. #include "CCGL.h" #include "CCAnimationCache.h" #include "CCTouch.h" +#include "CCUserDefault.h" #if CC_ENABLE_PROFILERS #include "support/CCProfiling.h" @@ -569,6 +570,7 @@ void CCDirector::purgeDirector() CCActionManager::sharedManager()->purgeSharedManager(); CCScheduler::purgeSharedScheduler(); CCTextureCache::purgeSharedTextureCache(); + CCUserDefault::purgeSharedUserDefault(); // OpenGL view m_pobOpenGLView->release(); diff --git a/cocos2dx/include/CCUserDefault.h b/cocos2dx/include/CCUserDefault.h index e664c51285..59bb034bbc 100644 --- a/cocos2dx/include/CCUserDefault.h +++ b/cocos2dx/include/CCUserDefault.h @@ -35,7 +35,7 @@ NS_CC_BEGIN; class CC_DLL CCUserDefault { public: - ~CCUserDefault() {} + ~CCUserDefault(); // get value methods bool getBoolForKey(const char* pKey); @@ -52,6 +52,7 @@ public: void setStringForKey(const char* pKey, std::string value); static CCUserDefault* sharedUserDefault(); + static void purgeSharedUserDefault(); const static std::string& getXMLFilePath(); private: diff --git a/cocos2dx/platform/android/CCFileUtils_android.cpp b/cocos2dx/platform/android/CCFileUtils_android.cpp index d4fd123d40..8637e74b66 100644 --- a/cocos2dx/platform/android/CCFileUtils_android.cpp +++ b/cocos2dx/platform/android/CCFileUtils_android.cpp @@ -104,7 +104,7 @@ int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out) return 0; } -const string CCFileUtils::getWriteablePath() +string CCFileUtils::getWriteablePath() { // the path is: /data/data/ + package name string dir("/data/data"); diff --git a/cocos2dx/platform/win32/CCFileUtils_win32.cpp b/cocos2dx/platform/win32/CCFileUtils_win32.cpp index d6de05c785..891f381e19 100644 --- a/cocos2dx/platform/win32/CCFileUtils_win32.cpp +++ b/cocos2dx/platform/win32/CCFileUtils_win32.cpp @@ -163,7 +163,7 @@ void CCFileUtils::setRelativePath(const char* pszRelativePath) CCAssert(0, "Have not implement!"); } -const string CCFileUtils::getWriteablePath() +string CCFileUtils::getWriteablePath() { // return the path that the exe file saved in diff --git a/cocos2dx/support/CCUserDefault.cpp b/cocos2dx/support/CCUserDefault.cpp index 995f9e863b..8423abca3c 100644 --- a/cocos2dx/support/CCUserDefault.cpp +++ b/cocos2dx/support/CCUserDefault.cpp @@ -133,6 +133,21 @@ CCUserDefault* CCUserDefault::m_spUserDefault = 0; string CCUserDefault::m_sFilePath = string(""); bool CCUserDefault::m_sbIsFilePathInitialized = false; +/** + * If the user invoke delete CCUserDefault::sharedUserDefault(), should set m_spUserDefault + * to null to avoid error when he invoke CCUserDefault::sharedUserDefault() later. + */ +CCUserDefault::~CCUserDefault() +{ + m_spUserDefault = NULL; +} + +void CCUserDefault::purgeSharedUserDefault() +{ + CC_SAFE_DELETE(m_spUserDefault); + m_spUserDefault = NULL; +} + bool CCUserDefault::getBoolForKey(const char* pKey) { const char* value = getValueForKey(pKey);