Advertisement

xml file reading trouble

Started by October 16, 2015 06:15 PM
1 comment, last by Evan Gordon 9 years, 2 months ago

So I'm working on implementing saving and reading for my current game I'm using PugiXML for reading and writing.

It's gone rather smoothly 'till recently, i needed a vector of XML documents, so i could store the information for the last few game map files that have been used. But pugiXML didnt like me stuffing documents into a vector dynamically, so i messed with things a bit and now its a vector of unique_ptr 's which i figured should work, but now even though everything compiles and no exceptions are thrown during runtime it seems like when i use push_back() it seems like the document is being deleted as soon as its being created and i have no clue as to why. ill post the code I've got below, any help is as always appreciated biggrin.png


#include "pugixml.hpp"
#include <vector>
#include <memory>

std::vector<std::unique_ptr<pugi::xml_document>> mapFile;
std::string mapFileName = "test.xml";
mapFile.push_back(std::unique_ptr<pugi::xml_document>(new pugi::xml_document()));//even after this call size is remaining 0
pugi::xml_parse_result result = mapFile[mapFile.size() - 1]->load_file(mapFileName.c_str());
if(!result)
{
	std::cout<< "Load result: "<< result.description()<< ", mesh name: "<< mapFile[mapFile.size() - 1]->child("mesh").attribute("name").value()<< "\n";
	try
	{throw;}
	catch(std::exception e)
	{
	        std::cout<<"Error: Failed to find "<< mapName << " the file was either moved or damaged.\n";
	}
}

try make_unique<pugi::xml_document>() for instantiation and replace .push_back with emplace_back.

If this post or signature was helpful and/or constructive please give rep.

// C++ Video tutorials

http://www.youtube.com/watch?v=Wo60USYV9Ik

// Easy to learn 2D Game Library c++

SFML2.2 Download http://www.sfml-dev.org/download.php

SFML2.2 Tutorials http://www.sfml-dev.org/tutorials/2.2/

// Excellent 2d physics library Box2D

http://box2d.org/about/

// SFML 2 book

http://www.amazon.com/gp/product/1849696845/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=1849696845&linkCode=as2&tag=gamer2creator-20

Advertisement

interesting. it works. not too sure why but regardless thanks :)

This topic is closed to new replies.

Advertisement