Skip to content

Instantly share code, notes, and snippets.

@ranisalt
Last active August 29, 2015 14:22
Show Gist options
  • Save ranisalt/db9a3b410d37f418f59e to your computer and use it in GitHub Desktop.
Save ranisalt/db9a3b410d37f418f59e to your computer and use it in GitHub Desktop.
Buggy file
#include "lodepng/lodepng.h"
#include "iomap.h"
bool IOMap::exportPNG(const Map& map, std::string filename)
{
uint32_t size = static_cast<uint32_t>(map._height) * static_cast<uint32_t>(map._width);
std::vector<uint8_t> bytes(size * 4);
for (uint16_t x = 0; x < map._height; ++x) {
for (uint16_t y = 0; y < map._width; ++y) {
auto index = map.index(x, y);
bytes[index] = 255;
bytes[index + 1] = 0;
bytes[index + 2] = 0;
bytes[index + 3] = 255;
}
}
if (lodepng::encode(filename, bytes, map._height, map._width) != 0) {
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment