diff --git a/src/graphics/Atlas.cpp b/src/graphics/Atlas.cpp index b7c87ab0..5cfac66b 100644 --- a/src/graphics/Atlas.cpp +++ b/src/graphics/Atlas.cpp @@ -42,7 +42,7 @@ void AtlasBuilder::add(string name, ImageData* image) { entries.push_back(atlasentry{name, shared_ptr(image)}); } -Atlas* AtlasBuilder::build(uint extrusion) { +Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) { unique_ptr sizes (new uint[entries.size() * 2]); for (uint i = 0; i < entries.size(); i++) { auto& entry = entries[i]; @@ -53,14 +53,18 @@ Atlas* AtlasBuilder::build(uint extrusion) { LMPacker packer(sizes.get(), entries.size()*2); sizes.reset(nullptr); - int width = 32; - int height = 32; + uint width = 32; + uint height = 32; while (!packer.buildCompact(width, height, extrusion)) { if (width > height) { height *= 2; } else { width *= 2; } + if (width > maxResolution || height > maxResolution) { + throw std::runtime_error("max atlas resolution "+ + std::to_string(maxResolution)+" exceeded"); + } } unordered_map regions; diff --git a/src/graphics/Atlas.h b/src/graphics/Atlas.h index 5da3ffa0..28168cef 100644 --- a/src/graphics/Atlas.h +++ b/src/graphics/Atlas.h @@ -38,7 +38,7 @@ public: AtlasBuilder() {} void add(std::string name, ImageData* image); - Atlas* build(uint extrusion); + Atlas* build(uint extrusion, uint maxResolution=8192); }; #endif // GRAPHICS_ATLAS_H_ \ No newline at end of file