在构建时工作,但在调试器中有问题
RapidXml Work when build but have problems in debugger
嗨,我使用rapidxml在我的游戏中加载地图,这就是我的加载类的样子它正常编译,但加载文件时,有时它崩溃,所以我想调试它,但调试器不喜欢我的功能,这是设置指针到XML文件中的数据。
#0 0042D5A6 rapidxml::xml_node<char>::first_node(this=0x0, name=0x484175 <_ZSt16__convert_from_vRKPiPciPKcz+4735349> "MapInfo", name_size=7, case_sensitive=true) (C:/.../rapidxml.hpp:942)
#1 00404E31 MapLoader::SetNodes(this=0x27fc1c) (C:...main.cpp:651)
#2 004032F6 main() (C:...main.cpp:267)
class MapLoader
{
public:
xml_document<> doc;
file<>xmlFile(char);
string ca,cb,cc,cd;
xml_node<> *test;
xml_node<> *root;
xml_node<> *mapinfo;
xml_node<> *name;
xml_node<> *date;
xml_node<> *msize;
xml_attribute<> *sizex;
xml_attribute<> *sizey;
xml_node<> *mapdata;
xml_node<> *layer;
xml_attribute<> *nr;
xml_node<> *tile;
xml_attribute<> *id;
xml_attribute<> *x;
xml_attribute<> *y;
void LoadFile(const char *filename);
void SetNodes();
void FillVector();
void SaveVector();
};
void MapLoader::SetNodes()
{
root=doc.first_node("root");
mapinfo=root->first_node("MapInfo"); //////debugger is pointing on this line
name=mapinfo->first_node("Name");
date=mapinfo->first_node("Date");
msize=mapinfo->first_node("Size");
sizex=msize->first_attribute("x");
sizey=msize->first_attribute("y");
mapdata=root->first_node("MapData");
layer=mapdata->first_node("Layer");
nr=layer->first_attribute("id");
tile=layer->first_node("Tile");
id=tile->first_attribute("id");
x=tile->first_attribute("x");
y=tile->first_attribute("y");
}
我能做些什么来修理它或类似的事情?
编辑:下面是我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<root>
<MapInfo>
<Name>Test</Name>
<Date>17.08.2014</Date>
<Size x="64" y="64"/>
</MapInfo>
<MapData>
<Layer nr="1">
<Tile id="1" x="32" y="32"/>
<Tile id="1" x="32" y="64"/>
<Tile id="1" x="512" y="64"/>
</Layer>
<Layer nr="2"/>
<Layer nr="3"/>
</MapData>
</root>
首先,检查返回的指针是否为NULL是一个好习惯。我的猜测是,"root"
在xml文件中缺失。
看一下rapidxml手册,因为大小写敏感也可能是一个问题。
编辑:我写了一个小程序,至少检查了Name
和Date
。
// Trying out rapid xml.
//
#include "rapidxml/rapidxml.hpp"
#include <cstdio>
#include <string>
#include <vector>
int main(int argc, char** argv) {
rapidxml::xml_document<> doc; // character type defaults to char
FILE* file = fopen("Test.xml", "r");
if (!file)
return 1;
// file exists.
// get the number of bytes.
fseek(file, 0, SEEK_END);
size_t sizeInBytes = ftell(file);
fseek(file, 0, SEEK_SET);
char* buffer = static_cast<char*>(malloc(sizeInBytes + 1)); // + 1 needed?
if (fread(buffer, 1LU, sizeInBytes, file) != sizeInBytes) {
perror("unexpected file lengthn");
fclose(file);
free(buffer);
return 1;
}
buffer[sizeInBytes] = 0;
// close the file.
fclose(file);
doc.parse<0>(buffer); // 0 means default parse flags
std::vector<std::string> nodeNames;
nodeNames.push_back("Name");
nodeNames.push_back("Date");
rapidxml::xml_node<>* node = doc.first_node("root");
for (size_t i = 0; i < nodeNames.size() && node; ++i) {
if (node->first_node(nodeNames[i].c_str()))
fprintf(stderr, "CantFindNode with name %s.n", nodeNames[i].c_str());
printf("Node %s found!n", nodeNames[i].c_str());
}
free(buffer);
return 0;
}
相关文章:
- 如果您在C++上有 Makefile 项目,如何在 VScode 中"fix"调试器?
- 无法取消引用超出范围的向量迭代器 - 有什么问题?
- C++ CDB 调试器问题
- 关于 TRIE 的 Leetcode 208。我的解构器有什么问题?它永远不会起作用
- 我的调试器说我有一个隔离错误错误,但无法告诉我在哪里,在非常特殊的情况下发生
- Linux Opensuse C 编译器问题.(无法初始化部分调试器的解压缩状态)
- 为什么调试器在排序前显示问题
- 在内部和外部与调试器之间运行有什么区别
- 我的解构器有问题
- 对于使用Cygwin GCC编译的C++程序,是否有免费的内存调试器
- 我的自定义迭代器有什么问题
- 有没有一个调试器可以让我在代码中后退一步
- qt5设计器,使用fileopen,在lineedit中显示文件路径,这样做是否有问题
- 函数返回类型名列表:<T>:迭代器有什么问题?
- C++链接器在Windows SDK中与DirectX有问题
- 我的字节数组到十六进制字符串转换器有什么问题,或者为什么它在写入文件时会在某个位置后剪切符号?
- 是否有模板调试器
- 这个简单的木炭填充器有什么问题
- 为什么我的Allegro 5地图编辑器有问题
- 在构建时工作,但在调试器中有问题