Compare commits

...

3 Commits

Author SHA1 Message Date
sigonasr2 e6315b1be8 Fixed memory buffer overflow and read the last value 2 years ago
sigonasr2 c98b50e4d1 Merge branch 'master' of http://sig.projectdivar.com/sigonasr2/TMXParser 2 years ago
sigonasr2 117ca03c96 Fixed memory buffer overflow and read the last value 2 years ago
  1. 15
      TMXParser.h

@ -1,9 +1,8 @@
#include <sstream> #include "pixelGameEngine.h"
#include <fstream> #include <strstream>
#include <map>
#include <vector> using namespace olc;
#include <iostream>
struct XMLTag{ struct XMLTag{
std::string tag; std::string tag;
@ -40,7 +39,6 @@ struct XMLTag{
struct LayerTag{ struct LayerTag{
XMLTag tag; XMLTag tag;
public:
std::vector<std::vector<int>> tiles; std::vector<std::vector<int>> tiles;
std::string str() { std::string str() {
std::string displayStr=tag.tag+"\n"+tag.FormatTagData(tag.data); std::string displayStr=tag.tag+"\n"+tag.FormatTagData(tag.data);
@ -129,9 +127,9 @@ class TMXParser{
while (f.good()) { while (f.good()) {
std::string data; std::string data;
f>>data; f>>data;
if (data.empty()) continue;
if (accumulator.length()>0) { if (accumulator.length()>0) {
//We're accumulating strings until we find '>'
accumulator+=" "+data; accumulator+=" "+data;
//Check if it ends with '>' //Check if it ends with '>'
if (data[data.length()-1]=='>') { if (data[data.length()-1]=='>') {
@ -150,6 +148,9 @@ class TMXParser{
data = data.substr(data.find(",")+1,std::string::npos); data = data.substr(data.find(",")+1,std::string::npos);
rowData.push_back(stoi(datapiece)); rowData.push_back(stoi(datapiece));
} }
if (data.length()) {
rowData.push_back(stoi(data));
}
parsedMapInfo.LayerData[parsedMapInfo.LayerData.size()-1].tiles.push_back(rowData); parsedMapInfo.LayerData[parsedMapInfo.LayerData.size()-1].tiles.push_back(rowData);
} }
} }

Loading…
Cancel
Save