From e040ef14ff7c0cabe45c63459bdc3a9f5e6ce9d4 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Tue, 13 Nov 2018 15:49:30 +0100 Subject: [PATCH] Better error when missing file --- src/parser/mtl.rs | 2 +- src/renderer.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/parser/mtl.rs b/src/parser/mtl.rs index 61b69db..68a50d0 100644 --- a/src/parser/mtl.rs +++ b/src/parser/mtl.rs @@ -71,7 +71,7 @@ impl LineParser for MtlParser { full_path.push(split[4].to_owned()); Ok(Element::Texture(first.to_owned(), full_path.to_str().unwrap().to_owned(), size)) } else { - Err(ParserError::UnexpectedKeyword(path.to_owned(), line_number, split[2].to_owned())) + Err(ParserError::UnexpectedKeyword(path.to_owned(), line_number, split[1].to_owned())) } }, diff --git a/src/renderer.rs b/src/renderer.rs index 19ace14..66f13c0 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -136,7 +136,11 @@ impl Renderer { /// Creates a SrgbTexture from a path to an image. pub fn make_texture(&self, path: &str) -> SrgbTexture2d { - let image = image::open(path).unwrap().to_rgba(); + let image = match image::open(path) { + Ok(r) => r.to_rgba(), + Err(e) => panic!("Error while opening file {}: {}", path, e), + }; + self.make_texture_from_buffer(image) }