I did understand your comment but if the layer had more or less elements then "tileAmount" then tilemaps would be corrupted, exported maps via Tiled has always layers with "height*width" elements in tilemaps. Am I not right?. So I thought that this kind of control would be unnecessary. Decoding of compressed and encoded tilemaps does not do any kind of control either and if you have corrupted map it will just segfault or will get some unexpected result. This code have been tested in our game where we are using tilemaps with plain XML format and everything worked ok ... But if you insist I can rewrite it and test for corrupted maps. I can also add some tests to TestCpp if you want to.