Hello,
I am tying to make a map loader for my game and want to load the tmx file format. nof i have sumbled across a problem with decompressing the data after i have decoded it. i know my decoded code works because it works just fine for the uncompressed file.
After decompressing i can see correct data, but after a while it fails/corrupts and it just repeats the last decoded values.
std::vector<std::string> dd = split(prop->value(), ' ');
std::string d;
for (std::string tmp : dd) // i want to remove the /n/r_ from the beginning of the string
{
if (tmp.size() > 10)
{
d = tmp;
break;
}
}
//decode
std::vector<char> tmp = base64_decode(d);
//decompress
std::vector<char> tmp2 = decompress_data(tmp);
// Copy the data over.
Layer.Data.resize(tmp2.size() / sizeof(unsigned int));
memcpy(&Layer.Data[0], &tmp2[0], tmp2.size());
int gg = 0; //break point
and my borrowed decompress function.
std::vector<char> decompress_data(const std::vector<char>& data)
{
// why not use http://www.cs.unc.edu/Research/compgeom/gzstream/#src
std::vector<char> newdata;
newdata.resize(5000);
//https://gist.github.com/arq5x/5315739
//// STEP 2.
//// inflate b into c
//// zlib struct
z_stream infstream;
infstream.zalloc = Z_NULL;
infstream.zfree = Z_NULL;
infstream.opaque = Z_NULL;
// setup "b" as the input and "c" as the compressed output
infstream.avail_in = (uInt)data.size(); // size of input
infstream.next_in = (Bytef *)data.data(); // input char array
infstream.avail_out = (uInt)newdata.size(); // size of output
infstream.next_out = (Bytef *)newdata.data(); // output char array
// the actual DE-compression work.
inflateInit(&infstream);
inflate(&infstream, Z_NO_FLUSH);
inflateEnd(&infstream);
//int i = 0;
return newdata;
}
i fixed the size to 5000 the actual map should contain 4000 entry’s. do any of you have an idea what is wrong here?
let me know if you need more information