Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Index out of bounds" when TMX data is missing newlines #48

Open
wlinna opened this issue Apr 12, 2021 · 4 comments
Open

"Index out of bounds" when TMX data is missing newlines #48

wlinna opened this issue Apr 12, 2021 · 4 comments

Comments

@wlinna
Copy link

wlinna commented Apr 12, 2021

Hello,

bevy_tiled crashes with Index out of bounds when a TMX's data (CSV) is missing new-lines. I used ldtk's TMX export to create my TMX file. Here's a small file to reproduce the issue:

<map version="1.4" tiledversion="1.4.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="4" height="4" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#696A79" nextlayerid="2" nextobjectid="1">
<tileset firstgid="1" name="Mountain_landscape" tilewidth="32" tileheight="32" tilecount="256" columns="16" objectalignment="topleft" margin="0" spacing="0">
    <image source="../../mountain_landscape.png" width="512" height="512"/>
</tileset>
<layer id="1" name="Ground" width="4" height="4" opacity="1">
    <data encoding="csv">
236,236,236,236,252,252,252,252,236,96,79,80,252,95,95,79
    </data>
</layer>
</map>

It works if I change data node to this:

    <data encoding="csv">
236,236,236,236,
252,252,252,252,
236,96,79,80,
252,95,95,79
    </data>

Here's how I use bevy_tiled

commands.spawn_bundle(bevy_tiled_prototype::TiledMapBundle {
      map_asset: assets.load("map/stuff/tiled/Arena01.tmx"),
      center: TiledMapCenter(true),
      origin: Transform::from_scale(Vec3::new(1.0, 1.0, 1.0)),
        ..Default::default()
});

Here's the error:
thread 'IO Task Pool (0)' panicked at 'index out of bounds: the len is 1 but the index is 1', /*/github.com-1ecc6299db9ec823/bevy_tiled_prototype-0.2.3/src/map.rs:186:46

It works if I break the lines manually or first import my TMX into Tiled editor and then save.

@wlinna wlinna changed the title "Index out of bounds" when TMX data is missing line breaks "Index out of bounds" when TMX data is missing newlines Apr 12, 2021
@dmtaub
Copy link
Collaborator

dmtaub commented Apr 17, 2021

@wlinna - it seems that this stems from an ambiguity in the Tiled TMX spec that doesn't specify whether newlines are meaningful. Take the assumption made by tiled-rs (which we rely on) that they are, coupled with ldtk's exporter flattening this CSV data , and you have the perfect storm for this bug.

We could write in a workaround, but it seems like that effort would be better served opening a PR to tiled-rs or ldtk...

@wlinna
Copy link
Author

wlinna commented Apr 23, 2021

Thanks for the info. I'll report there

@wlinna
Copy link
Author

wlinna commented May 2, 2021

A new version of rs-tiled addressing the issue has been published. I haven't tried it with bevy_tiled yet though (cargo-lock specifies 0.9.4 anyway)

@wlinna
Copy link
Author

wlinna commented May 3, 2021

Alright, I found an easy way to update a transitive dependency (yay):
cargo update -p tiled --precise 0.9.5

Now it works. This issue can be closed once you upgrade tiled.

Again, thanks for the information – it helped me report the issue

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

No branches or pull requests

2 participants