Skip to content

Commit b1a786b

Browse files
committed
Canonicalize CARGO_MANIFEST_DIR in case it's set as a relpath and causes crashes FileAssetIo's strip_prefix.
1 parent f1be89d commit b1a786b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

crates/bevy_asset/src/io/file_asset_io.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ impl FileAssetIo {
6464
/// instead. It's set by cargo when running with `cargo run`.
6565
pub fn get_base_path() -> PathBuf {
6666
if let Ok(manifest_dir) = env::var("CARGO_MANIFEST_DIR") {
67-
PathBuf::from(manifest_dir)
67+
// Some Windows software don't support canonicalized path names, so let's avoid them
68+
// unless the path is relative, in which case we currently need to make it absolute
69+
// (See more: https://github.com/rust-lang/rust/issues/59117 )
70+
if Path::new(&manifest_dir).is_relative() {
71+
fs::canonicalize(&manifest_dir).unwrap_or_else(|_| PathBuf::from(manifest_dir))
72+
} else {
73+
PathBuf::from(manifest_dir)
74+
}
6875
} else {
6976
env::current_exe()
7077
.map(|path| {

0 commit comments

Comments
 (0)