Skip to content

Commit

Permalink
Check asset-path existence. Previously App just crashed if not (#345)
Browse files Browse the repository at this point in the history
* 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 Aug 26, 2020
1 parent b718a20 commit 93040ef
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 93040ef

Please sign in to comment.