c++ - RapidXml Work when build but have problems in debugger -
hi use rapidxml load map in game how class loading looks it's compiling when loading file crashing wanted debug debugger dont function setting pointers data in xml file.
#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 pointing on 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"); } what can repair or that?
edit: here xml file:
<?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>
first of practice check null returned pointer. guess be, "root" missing in xml file.
take @ the manual of rapidxml because case sensitivity can issue.
edit:
i wrote small program , checked @ least name , date. works me.
// 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 char file* file = fopen("test.xml", "r"); if (!file) return 1; // file exists. // 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 length\n"); fclose(file); free(buffer); return 1; } buffer[sizeinbytes] = 0; // close 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"); (size_t = 0; < nodenames.size() && node; ++i) { if (node->first_node(nodenames[i].c_str())) fprintf(stderr, "cantfindnode name %s.\n", nodenames[i].c_str()); printf("node %s found!\n", nodenames[i].c_str()); } free(buffer); return 0; }
Comments
Post a Comment