When I use rapidjson document as member variable and do this:
class Test
{
rapidjson::Document m_jsonDocument;
public:
void f()
{
// WORKS FINE
rapidjson::Document document;
if (document.Parse<0>("{ \"hello\" : \"world\" }").HasParseError())
printf("ERROR PARSING JSON\n");
else
printf("%s\n", document["hello"].GetString());
// BUT HERE THROWS, WHY?
if (m_jsonDocument.Parse<0>("{ \"hello\" : \"world\" }").HasParseError())
printf("ERROR PARSING JSON\n");
else
printf("%s\n", m_jsonDocument["hello"].GetString());
}
};
When I call if (m_jsonDocument.Parse<0>("{ \"hello\" : \"world\" }").HasParseError())
app crashes on line flags_ = defaultFlags[type];
in document.h
in CTOR GenericValue(Type type)
. Visual Studio debugger says "Unable to read memory." for _flags
. What is the problem? What is the difference between member variable and local variable?
EDIT: I set f
as a callback using setResponseCallback
defined here and f
is being called as a callback using dispatchResponseCallbacks
defined here.