fixed #455: release CCUserDefault at end & fix a bug when the user delete CCUserDefault carelessly

This commit is contained in:
minggo 2011-05-06 17:46:19 +08:00
parent bfcee3e2ae
commit e14040730b
5 changed files with 21 additions and 3 deletions

View File

@ -46,6 +46,7 @@ THE SOFTWARE.
#include "CCGL.h" #include "CCGL.h"
#include "CCAnimationCache.h" #include "CCAnimationCache.h"
#include "CCTouch.h" #include "CCTouch.h"
#include "CCUserDefault.h"
#if CC_ENABLE_PROFILERS #if CC_ENABLE_PROFILERS
#include "support/CCProfiling.h" #include "support/CCProfiling.h"
@ -569,6 +570,7 @@ void CCDirector::purgeDirector()
CCActionManager::sharedManager()->purgeSharedManager(); CCActionManager::sharedManager()->purgeSharedManager();
CCScheduler::purgeSharedScheduler(); CCScheduler::purgeSharedScheduler();
CCTextureCache::purgeSharedTextureCache(); CCTextureCache::purgeSharedTextureCache();
CCUserDefault::purgeSharedUserDefault();
// OpenGL view // OpenGL view
m_pobOpenGLView->release(); m_pobOpenGLView->release();

View File

@ -35,7 +35,7 @@ NS_CC_BEGIN;
class CC_DLL CCUserDefault class CC_DLL CCUserDefault
{ {
public: public:
~CCUserDefault() {} ~CCUserDefault();
// get value methods // get value methods
bool getBoolForKey(const char* pKey); bool getBoolForKey(const char* pKey);
@ -52,6 +52,7 @@ public:
void setStringForKey(const char* pKey, std::string value); void setStringForKey(const char* pKey, std::string value);
static CCUserDefault* sharedUserDefault(); static CCUserDefault* sharedUserDefault();
static void purgeSharedUserDefault();
const static std::string& getXMLFilePath(); const static std::string& getXMLFilePath();
private: private:

View File

@ -104,7 +104,7 @@ int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
return 0; return 0;
} }
const string CCFileUtils::getWriteablePath() string CCFileUtils::getWriteablePath()
{ {
// the path is: /data/data/ + package name // the path is: /data/data/ + package name
string dir("/data/data"); string dir("/data/data");

View File

@ -163,7 +163,7 @@ void CCFileUtils::setRelativePath(const char* pszRelativePath)
CCAssert(0, "Have not implement!"); CCAssert(0, "Have not implement!");
} }
const string CCFileUtils::getWriteablePath() string CCFileUtils::getWriteablePath()
{ {
// return the path that the exe file saved in // return the path that the exe file saved in

View File

@ -133,6 +133,21 @@ CCUserDefault* CCUserDefault::m_spUserDefault = 0;
string CCUserDefault::m_sFilePath = string(""); string CCUserDefault::m_sFilePath = string("");
bool CCUserDefault::m_sbIsFilePathInitialized = false; 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) bool CCUserDefault::getBoolForKey(const char* pKey)
{ {
const char* value = getValueForKey(pKey); const char* value = getValueForKey(pKey);