在 Cocos2dx 中使用 RapidJson,它在 IOS 中的 Accept(writer) 中崩溃
Use RapidJson in Cocos2dx, it crash in Accept(writer) in IOS
我用的是Cocos2dx 3.9;并使用 rapidjson 将 CCDictionary 转换为字符串;我发现它会在 value->Accept(wirter) 在真机中崩溃;但会在模拟器中工作。
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value->Accept(writer);
这是我的错误,我使用:
rapidjson::Value *value = KSCCJsonRapid::jsonValueFromDictionary(dic);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value->Accept(writer);
std::string jsonString = buffer.GetString();
但在
static rapidjson::Value* jsonValueFromDictionary(cocos2d::CCDictionary *dic, rapidjson::Document *document = NULL);
,我新建一个文档,然后删除;在真机中,内存是有限的;所以这个值是无效的。
可以通过以下方式更正:
rapidjson::Document *document = new Document();
rapidjson::Value *value = KSCCJsonRapid::jsonValueFromDictionary(dic, document);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value->Accept(writer);
std::string jsonString = buffer.GetString();
delete value;
delete document;
我用的是Cocos2dx 3.9;并使用 rapidjson 将 CCDictionary 转换为字符串;我发现它会在 value->Accept(wirter) 在真机中崩溃;但会在模拟器中工作。
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value->Accept(writer);
这是我的错误,我使用:
rapidjson::Value *value = KSCCJsonRapid::jsonValueFromDictionary(dic);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value->Accept(writer);
std::string jsonString = buffer.GetString();
但在
static rapidjson::Value* jsonValueFromDictionary(cocos2d::CCDictionary *dic, rapidjson::Document *document = NULL);
,我新建一个文档,然后删除;在真机中,内存是有限的;所以这个值是无效的。 可以通过以下方式更正:
rapidjson::Document *document = new Document();
rapidjson::Value *value = KSCCJsonRapid::jsonValueFromDictionary(dic, document);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
value->Accept(writer);
std::string jsonString = buffer.GetString();
delete value;
delete document;