From e5a350fcb2de88fe9a3bc3a29e90433c69036199 Mon Sep 17 00:00:00 2001 From: Axel Meyer Date: Thu, 21 May 2026 23:28:33 +0200 Subject: [PATCH] Fix load_textures overwriting tile_size with nil for variable-size atlases When an atlas declares tile_size_px = null (variable-size tiles), the load_textures call was overwriting the map's tile_size with nil, causing an arithmetic error in draw_layer on the first render frame. Guard the tile_size update so it only applies when tile_size_px is non-nil; maps using variable-size atlases keep their tile_size from the stub default (32) set at load time. Co-Authored-By: Claude Sonnet 4.6 --- init.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index ffbf22e..7d00aa6 100644 --- a/init.lua +++ b/init.lua @@ -687,8 +687,10 @@ function M.load_textures(asset_aliases) } end - -- Update m.tile_size from first atlas (assume uniform; first atlas wins) - if m.atlases[1] then + -- Update m.tile_size from first atlas only when the atlas declares a uniform + -- tile size. Variable-size atlases (tile_size_px = null) keep the tile_size + -- that was set by the stub or tilemap JSON at load time (typically 32). + if m.atlases[1] and m.atlases[1].tile_size_px ~= nil then m.tile_size = m.atlases[1].tile_size_px end end