From 649c42ddc4c11728490d9f003f7de04333bedc70 Mon Sep 17 00:00:00 2001 From: Piotr Date: Thu, 15 Oct 2020 17:36:20 +0200 Subject: [PATCH] Detect wrong image path --- doppler/src/utils.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/doppler/src/utils.rs b/doppler/src/utils.rs index 8c806ed..d75c2fc 100644 --- a/doppler/src/utils.rs +++ b/doppler/src/utils.rs @@ -1,9 +1,14 @@ use gl; use image2::image::Image; use image2::{io, ImagePtr, Rgb, Rgba}; -use log::info; +use log::{info,error}; use std::os::raw::c_void; +pub fn path_exists(path: &std::path::Path) -> bool { + let meta = std::fs::metadata(path); + meta.is_ok() +} + pub unsafe fn load_texture(path: &str, file_format: &str) -> u32 { info!("Loading texture: {}", path); let mut id = 0; @@ -75,6 +80,9 @@ pub unsafe fn load_cubemap(faces: &[&str]) -> u32 { gl::BindTexture(gl::TEXTURE_CUBE_MAP, texture_id); for (i, face) in faces.iter().enumerate() { + if !path_exists(std::path::Path::new(&face)) { + error!("There is no file {}", face); + } let (data, dim) = { let img: ImagePtr = io::read_u8(face).unwrap(); let img_data = img.data().to_vec();