Skip to content

Commit 89b34ba

Browse files
committed
Fix #3162
1 parent d86404e commit 89b34ba

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

axmol/2d/TMXXMLParser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,17 @@ Rect TMXTilesetInfo::getRectForGID(uint32_t gid)
8888
// max_x = (int)((_imageSize.width - _margin*2 + _spacing) / (_tileSize.width + _spacing));
8989
// but in editor "Tiled", _margin variable only effect the left side
9090
// for compatible with "Tiled", change the max_x calculation
91+
if ((_tileSize.width + _spacing) == 0)
92+
{
93+
AXLOGE("TMXTilesetInfo::getRectForGID - invalid tile size or spacing (width + spacing == 0)");
94+
return rect;
95+
}
9196
int max_x = (int)((_imageSize.width - _margin + _spacing) / (_tileSize.width + _spacing));
97+
if (max_x == 0)
98+
{
99+
AXLOGE("TMXTilesetInfo::getRectForGID - invalid tileset layout (calculated column count == 0)");
100+
return rect;
101+
}
92102

93103
rect.origin.x = (gid % max_x) * (_tileSize.width + _spacing) + _margin;
94104
rect.origin.y = (gid / max_x) * (_tileSize.height + _spacing) + _margin;

0 commit comments

Comments
 (0)