From b1a786bb0faf9f7a3163cc86fe04d2e5c23c3bd9 Mon Sep 17 00:00:00 2001 From: Pyry Kontio Date: Mon, 15 Aug 2022 20:42:25 +0900 Subject: [PATCH] Canonicalize CARGO_MANIFEST_DIR in case it's set as a relpath and causes crashes FileAssetIo's strip_prefix. --- crates/bevy_asset/src/io/file_asset_io.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/bevy_asset/src/io/file_asset_io.rs b/crates/bevy_asset/src/io/file_asset_io.rs index 59447dfac5031..e44ba82254275 100644 --- a/crates/bevy_asset/src/io/file_asset_io.rs +++ b/crates/bevy_asset/src/io/file_asset_io.rs @@ -64,7 +64,14 @@ impl FileAssetIo { /// instead. It's set by cargo when running with `cargo run`. pub fn get_base_path() -> PathBuf { if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") { - PathBuf::from(manifest_dir) + // Some Windows software don't support canonicalized path names, so let's avoid them + // unless the path is relative, in which case we currently need to make it absolute + // (See more: https://github.com/rust-lang/rust/issues/59117 ) + if Path::new(&manifest_dir).is_relative() { + fs::canonicalize(&manifest_dir).unwrap_or_else(|_| PathBuf::from(manifest_dir)) + } else { + PathBuf::from(manifest_dir) + } } else { env::current_exe() .map(|path| {