Open Pieresqi opened 1 week ago
Windows platform doesn't support /
path, there is no correct path for entire computer, the path should start from disk letter for local paths like C:/
I found where the error occurred, and it happens because the read_directory()
function in crates/bevy_asset/src/io/file/file_asset.rs
tries to run strip_prefix()
on the path /home
, which has no prefix.
After verifying that the inputted path is a directory (file_asset.rs:53
), we get this bit of code:
let root_path = self.root_path.clone();
let mapped_stream = read_dir.filter_map(move |f| {
f.ok().and_then(|dir_entry| {
let path = dir_entry.path();
if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
if ext.eq_ignore_ascii_case("meta") {
return None;
}
}
let relative_path = path.strip_prefix(&root_path).unwrap();
Some(relative_path.to_owned())
})
});
let read_dir: Box<PathStream> = Box::new(mapped_stream);
Ok(read_dir)
The issue happens when assigning the relative_path
variable.
let relative_path = path.strip_prefix(&root_path).unwrap();
Normally, loading a file would look like this:
root_path: "/path/to/project/assets"
path: "/path/to/project/assets/models/torus/torus.gltf"
In this case, the path is changed to just be models/torus/torus.gltf
by running path.strip_prefix(&root_path)
, and the filter_map goes to the next item.
When you try to load the folder /
, this is instead what loading looks like
root_path: "/path/to/project/assets"
path: "/home"
Running path.strip_prefix(&root_path)
here returns an Error type because "/home" does not contain root_path.
\
I think the way to solve this would be to either throw some kind of error warning that trying to load everything in the system is most likely a bad idea, or by using a crate such as pathdiff to get the relative path, which should return a path along the lines of ../../../../../
whenever encountering /
.
Bevy version
0.14.0-rc.3
[Optional] Relevant system information
SystemInfo { os: "Windows 11 Enterprise", kernel: "22631", cpu: "AMD Ryzen 9 5900X 12-Core Processor", core_count: "12", memory: "63.9 GiB" }
AdapterInfo { name: "NVIDIA GeForce GTX 1080", vendor: 4318, device: 7040, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "555.99", backend: Vulkan }
What you did
I tried loading folder
What went wrong
It panicked and wrote into console:
While app just ran with this panic I don't think is should panic...
It's intended behaviour ? Maybe write better panic message ??
Additional information