diff --git a/cocos/base/CCUserDefault.cpp b/cocos/base/CCUserDefault.cpp index cb3f713942..6b4da15a60 100644 --- a/cocos/base/CCUserDefault.cpp +++ b/cocos/base/CCUserDefault.cpp @@ -324,7 +324,7 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) encodedData = (const char*)(node->FirstChild()->Value()); } - Data ret = defaultValue; + Data ret; if (encodedData) { @@ -335,6 +335,10 @@ Data UserDefault::getDataForKey(const char* pKey, const Data& defaultValue) ret.fastSet(decodedData, decodedDataLen); } } + else + { + ret = defaultValue; + } if (doc) delete doc;