Hi guys, im trying to load a map with rapidxml, it compiles alright but when i call the function , i get a error.
Here is the code:
void LoadMap(std::string mapname, Block *blocks[] )
{
//Loads a level from xml file
//Load the file
std::ifstream mapFile(mapname);
if(!mapFile)
throw "Could not load tileset: " + mapname;
//Dump contents of file into a string
std::string xmlContents;
//Blocked out of preference
{
std::string line;
while(std::getline(mapFile, line))
xmlContents += line;
}
//Convert string to rapidxml readable char*
std::vector<char> xmlData = std::vector<char>(xmlContents.begin(), xmlContents.end());
xmlData.push_back('\0');
//Create a parsed document with &xmlData[0] which is the char*
rapidxml::xml_document<> doc;
doc.parse<rapidxml::parse_no_data_nodes>(&xmlData[0]);
//Get the root node
rapidxml::xml_node<>* root = doc.first_node();
std::string imagepath;
//Load each necessary tileset
rapidxml::xml_node<>* tileset = root->first_node("tileset");
while(tileset)
{
imagepath = tileset->first_attribute("name")->value();
}
sf::Texture texture;
texture.loadFromFile(imagepath);
//Columns and rows (of tileset image)
int columns = texture.getSize().x / 32;
int rows = texture.getSize().y / 32;
std::vector <sf::Rect<int> > subRects;
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < columns; x++)
{
sf::Rect <int> rect;
rect.top = y * 32;
rect.height = y * 32 + 32;
rect.left = x * 32;
rect.width = x * 32 + 32;
subRects.push_back(rect);
}
}
rapidxml::xml_node<>* tile = root->first_node("tile");
int block_type = -1;
int x = 0;
int y = 0;
int n = 0;
while(tile)
{
block_type = atoi(tile->first_attribute("gid")->value());
blocks[n] = new Block( n, block_type, x, y);
x += 32;
cout<<"ID: "<<n<<" Block type: "<<block_type<<" X,Y: "<<x<<","<<y;
if( x >= SCREEN_WIDTH)
{
x = 0;
y += 32;
}
n++;
tile = tile->next_sibling("tile");
}
mapFile.close();
}
This is how i call it:
Block* blocks[TOTAL_TILES];
LoadMap("spawn.tmx", blocks);
Debug error: R6010
-abort() has been called
and i can only click abort, retry and ignore