StarArawn/bevy_tiled

Incomplete path passed to tiled::parse_with_path

SarthakSingh31 opened this issue · 3 comments

├── Cargo.toml
├── src/
│      └──  main.rs
├── assets/
│       ├── world.tmx
│       ├── tiles_world.tsx
│       └── tiles_world.png

For a project with the above file structure and where tiles_world.tsx is an external tileset used by world.tmx

when we try to run asset_server.load("working_map.tmx")

bevy_tiled/src/loader.rs

Lines 25 to 32 in 2af6208

fn load<'a>(
&'a self,
bytes: &'a [u8],
load_context: &'a mut LoadContext,
) -> BoxedFuture<'a, Result<(), anyhow::Error>> {
Box::pin(async move {
let path = load_context.path();
let mut map = Map::try_from_bytes(path, bytes.into())?;

load_context.path() returns the path relative to the assets folder (i.e. "world.tmx")

bevy_tiled/src/map.rs

Lines 53 to 54 in 2af6208

pub fn try_from_bytes(asset_path: &Path, bytes: Vec<u8>) -> Result<Map> {
let map = tiled::parse_with_path(BufReader::new(bytes.as_slice()), asset_path).unwrap();

this asset_path is then used in tiled::parse_with_path to resolve external tilesets which panics with

Other("External tileset file not found: \"tiles_world.tsx\"")

because it will try to look for "<execution path>/tiles_world.tsx" instead of "<execution path>/assets/tiles_world.tsx"

shouldn't the path be relative to the world file and completely unrelated to the working directory?

while #52 fixes this when the project is run from its root, it is still broken when the project is e.g. a workspace member.

I am currently short on time so I can't submit a PR anytime soon, but if this is still broken when I have free time again I'll take a look at it