- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
当我关闭我的应用程序时,我一直收到这个消息。我知道它与 JsonCpp 有关,因为它仅在我使用 Json 值时发生。
我认为这与我如何创建 json 值有关,但由于没有任何教程,我不知道我应该怎么做
我的代码目前是:
static Json::Value root; // will contains the root value after parsing.
unsigned int WindowSettings::WindowWidth = 800;
unsigned int WindowSettings::WindowHeight = 600;
bool WindowSettings::FullScreen = false;
unsigned short WindowSettings::AntiAliasing = 16;
bool WindowSettings::VSync = false;
short WindowSettings::FrameRateLimit = 60;
AspectRatios WindowSettings::AspectRatio = ar4p3;
Resolutions WindowSettings::Resolution = r800x600;
Json::Value WindowSettings::root = Json::Value();
void WindowSettings::remakeDefault()
{
root["WindowWidth"] = WindowWidth;
root["WindowHeight"] = WindowHeight;
root["FullScreen"] = FullScreen;
root["AntiAliasing"] = AntiAliasing;
root["VSync"] = VSync;
root["FrameRateLimit"] = FrameRateLimit;
root["AspectRatio"] = AspectRatio;
root["Resolution"] = Resolution;
saveToFile("conf.json");
}
bool WindowSettings::saveToFile(const std::string &fileName)
{
Json::FastWriter writer;
// Make a new JSON document for the configuration. Preserve original comments.
std::string outputConfig = writer.write( root );
std::ofstream myfile;
myfile.open (fileName.c_str(), std::ios::out | std::ios::trunc | std::ios::binary );
if (myfile.is_open())
{
myfile << outputConfig.c_str();
myfile.close();
}
return true;
}
我应该补充一点,当我不这样做时不会发生这种情况: root["blah"] = foo;
最佳答案
编辑
发现这是一个已知问题(例如 here)
Turns out this is due to some sort of bug in jsoncpp which makes it not work as global variables. Which I guess the old notion that global variables are bad news is hard to get away from. S*o I wrapped up all my json away from being globals and it works fine now. Less globals is certainly a good move*, whatever the case.
错误报告在这里 (zeromus):http://sourceforge.net/tracker/index.php?func=detail&aid=2934500&group_id=144446&atid=758826
状态是固定的:
I have fixed it by representing the fact that a Value has an implicit dependency on a given instance of ValueAllocator by giving it a ValueAllocatorHandle which is just reference counted and takes care of deleting a heap allocated allocator when the last Value goes out of scope.
一般来说,我怀疑构造函数/析构函数访问虚拟成员导致 UB(并且可能根本缺少虚拟析构函数)。
由于您提到应用程序关闭,static Json::Value root
是一个可疑对象。如果这是在 linux 上,我会在 valgrind 下运行它
sudo -E valgrind --db--attach=yes ./yourprogram
这可以确保您拥有必要的权限。当然,使用调试信息进行编译有很大帮助。
关于c++ - 使用 JSonCpp 调用纯虚函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7948821/
我有一个特别的问题想要解决,我不确定是否可行,因为我找不到任何信息或正在完成的示例。基本上,我有: class ParentObject {}; class DerivedObject : publi
在我们的项目中,我们配置了虚 URL,以便用户可以在地址栏中输入虚 URL,这会将他们重定向到原始 URL。 例如: 如果用户输入'http://www.abc.com/partner ',它会将它们
我是一名优秀的程序员,十分优秀!