Skip to content

Commit

Permalink
Check asset-path existence. Previously App just crashed if not (bevye…
Browse files Browse the repository at this point in the history
…ngine#345)

* Check asset-path existence. Previously App just crashed if not

* rustfmt

* Relegated Error-message to ChannelAssetHandler

* Removed needless return statement
  • Loading branch information
Telzhaak authored and mrk-its committed Oct 6, 2020
1 parent 37e0ad3 commit ae1c0e4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions crates/bevy_asset/src/load_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,18 @@ where
}

fn load_asset(&self, load_request: &LoadRequest) -> Result<TAsset, AssetLoadError> {
let mut file = File::open(&load_request.path)?;
let mut bytes = Vec::new();
file.read_to_end(&mut bytes)?;
let asset = self.loader.from_bytes(&load_request.path, bytes)?;
Ok(asset)
match File::open(&load_request.path) {
Ok(mut file) => {
let mut bytes = Vec::new();
file.read_to_end(&mut bytes)?;
let asset = self.loader.from_bytes(&load_request.path, bytes)?;
Ok(asset)
}
Err(e) => Err(AssetLoadError::Io(std::io::Error::new(
e.kind(),
format!("{}", load_request.path.display()),
))),
}
}
}

Expand Down

0 comments on commit ae1c0e4

Please sign in to comment.