Skip to content

Commit 2ed4563

Browse files
committedAug 9, 2016
Warn on big image dimensions, fixes #14
1 parent 15fae27 commit 2ed4563

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed
 

Diff for: ‎TileGenerator.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,17 @@ void TileGenerator::createImage()
355355
{
356356
m_mapWidth = (m_xMax - m_xMin + 1) * 16;
357357
m_mapHeight = (m_zMax - m_zMin + 1) * 16;
358-
m_image = gdImageCreateTrueColor((m_mapWidth * m_zoom) + m_border, (m_mapHeight * m_zoom) + m_border);
358+
int image_width, image_height;
359+
image_width = (m_mapWidth * m_zoom) + m_border;
360+
image_height = (m_mapHeight * m_zoom) + m_border;
361+
if(image_width > 4096 || image_height > 4096)
362+
std::cerr << "Warning: The width or height of the image to be created exceeds 4096 pixels!"
363+
<< " (Dimensions: " << image_width << "x" << image_height << ")"
364+
<< std::endl;
365+
m_image = gdImageCreateTrueColor(image_width, image_height);
359366
m_blockPixelAttributes.setWidth(m_mapWidth);
360367
// Background
361-
gdImageFilledRectangle(m_image, 0, 0, (m_mapWidth * m_zoom) + m_border - 1, (m_mapHeight * m_zoom) + m_border -1, color2int(m_bgColor));
368+
gdImageFilledRectangle(m_image, 0, 0, image_width - 1, image_height - 1, color2int(m_bgColor));
362369
}
363370

364371
void TileGenerator::renderMap()

0 commit comments

Comments
 (0)