From ab03a493cf2257bfab9a61cfb1b5a872c2c9fe96 Mon Sep 17 00:00:00 2001 From: Dave Corley Date: Thu, 24 Oct 2024 23:03:42 -0700 Subject: [PATCH] FEAT: Fix `find_vfs_texture` to not terminate the application on failing to find a texture --- src/map_data.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/map_data.rs b/src/map_data.rs index 6e5e9fd..a621582 100644 --- a/src/map_data.rs +++ b/src/map_data.rs @@ -131,18 +131,20 @@ impl MapData { pub fn find_vfs_texture(name: &str, config: &Ini) -> Option { let extensions = ["dds", "tga", "png"]; - Some( - extensions - .iter() - .flat_map(|extension| { - println!("Searching for texture: {name}"); - find_file(config, format!("Textures/{}.{}", name, extension).as_str()) - }) - .next() - .expect("Texture not found! This map is using a texture which isn't in your openmw vfs!") - .to_string_lossy() - .to_string(), - ) + extensions + .iter() + .find_map(|extension| { + let full_name = format!("Textures/{}.{}", name, extension); + println!("Searching for texture: {}", full_name); + match find_file(config, full_name.as_str()) { + std::result::Result::Ok(path) => Some(path.to_string_lossy().to_string()), + Err(_) => { None } + } + }) + .or_else(|| { + eprintln!("ERROR: Texture not found! This map is using a texture which isn't in your OpenMW VFS: {}.[dds/tga/png]", name); + None + }) } pub fn find_textures_in_vfs(textures: &HashSet) -> HashSet {