Skip to content

Work out the tileset columns when the columns attribute is missing - #196

Merged
fallahn merged 1 commit into
fallahn:masterfrom
vtxe02023274:fix/missing-columns-attribute
Dec 4, 2026
Merged

fallahn merged 1 commit into
fallahn:masterfrom
vtxe02023274:fix/missing-columns-attribute

Conversation

@vtxe02023274

Copy link
Copy Markdown
Contributor

Tiled before 0.15 writes tilecount on the tileset but not columns. tmxlite reads the missing attribute as 0, and when the tileset doesn't list every tile, createMissingTile divides by m_columnCount, so loading such a map crashes with a division by zero (SIGFPE):

tmxlite/src/Tileset.cpp:477:33: runtime error: division by zero
    #0 tmx::Tileset::createMissingTile(unsigned int) tmxlite/src/Tileset.cpp:477
    #1 tmx::Tileset::parse(pugi::xml_node, tmx::Map*) tmxlite/src/Tileset.cpp:237

Changes:

  • When the columns attribute is missing, work it out from the image width the same way Tiled does (Tileset::columnCountForWidth: (width - margin + spacing) / (tileWidth + spacing)), so the tiles get their image positions.
  • Skip the image position in createMissingTile when the column count is 0, like parseTileNode already does.

Test: maps/no_columns.tmx has two tilesets without columns (one with spacing and margin) and testTilesetWithoutColumns checks the column counts and tile image positions. Without the fix ParseTest crashes at that test; with it every check passes (built with -fsanitize=address,undefined).

@fallahn
fallahn merged commit d863071 into fallahn:master Dec 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants