Hi.
When you tick 'infinite' in Tiled, trying to load the tilemap will result in a confusing error:
Traceback (most recent call last):
File "E:\dev\wW\main.py", line 69, in <module>
main()
File "E:\dev\wW\main.py", line 64, in main
window.setup()
File "E:\dev\wW\main.py", line 40, in setup
self.tile_map = arcade.load_tilemap(map_name, TILE_SCALING, layer_options)
File "E:\dev\wW\venv\lib\site-packages\arcade\tilemap\tilemap.py", line 829, in load_tilemap
return TileMap(
File "E:\dev\wW\venv\lib\site-packages\arcade\tilemap\tilemap.py", line 191, in __init__
self._process_layer(layer, global_options, layer_options)
File "E:\dev\wW\venv\lib\site-packages\arcade\tilemap\tilemap.py", line 216, in _process_layer
processed = self._process_tile_layer(layer, **options)
File "E:\dev\wW\venv\lib\site-packages\arcade\tilemap\tilemap.py", line 592, in _process_tile_layer
for row_index, row in enumerate(map_array):
TypeError: 'NoneType' object is not iterable
The code:
map_name = "assets/main_map.json"
layer_options = {
"platforms": {
"use_spatial_hash": True,
},
}
self.tile_map = arcade.load_tilemap(map_name, TILE_SCALING, layer_options)
I went on a exploration of arcade and pytiled_parser code and I found out that when you tick 'infinite' in tiled, the dict stored in the json file has a different structure: in a finite map, each of the "layers" element has a "data" entry, but in an infinite map each of the "layers" element has a "chunks" entry instead, and each of the chunk has a "data" entry. The pytiled parser handles it with ease, but the function _process_tile_layer always relies on the "data" entry without regard to the existence of a "chunks" entry.
tilemap.py line 589:
map_array = layer.data
Obviously with an infinite map the layer.data is None because the data you want is located somewhere like [chunk.data for chunk in layer.chunks]
So the below code fails, causing the error I mentionned earlier:
for row_index, row in enumerate(map_array):
Is it intentionnal? Changing the map to a finite version were easily done, but I wasted about an hour of frustration to figure that out. Did I miss the part in the documentation mentionning the issue with infinite map? I saw there is an explicit error message when trying to load a map with duplicate layer names so I guess it would make sense to also yield an explicit error message when trying to load infinite maps if the intention is to not support these.
Hi.
When you tick 'infinite' in Tiled, trying to load the tilemap will result in a confusing error:
The code:
I went on a exploration of arcade and pytiled_parser code and I found out that when you tick 'infinite' in tiled, the dict stored in the json file has a different structure: in a finite map, each of the "layers" element has a "data" entry, but in an infinite map each of the "layers" element has a "chunks" entry instead, and each of the chunk has a "data" entry. The pytiled parser handles it with ease, but the function _process_tile_layer always relies on the "data" entry without regard to the existence of a "chunks" entry.
tilemap.py line 589:
map_array = layer.dataObviously with an infinite map the layer.data is None because the data you want is located somewhere like [chunk.data for chunk in layer.chunks]
So the below code fails, causing the error I mentionned earlier:
for row_index, row in enumerate(map_array):Is it intentionnal? Changing the map to a finite version were easily done, but I wasted about an hour of frustration to figure that out. Did I miss the part in the documentation mentionning the issue with infinite map? I saw there is an explicit error message when trying to load a map with duplicate layer names so I guess it would make sense to also yield an explicit error message when trying to load infinite maps if the intention is to not support these.