From b561ffdfc658f9bd9da627c0ba6986a1382b7bd8 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 9 Jan 2024 01:11:26 -0800 Subject: [PATCH] join threads to see errors --- src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index bab609d..9f9d507 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1056,6 +1056,7 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> let mut zippyt=bsp.pack.into_zip().into_inner().unwrap(); let tree=&vpk_index.tree; std::thread::scope(move|s|{ + let mut thread_handles=Vec::new(); for texture_name in deduplicate{ let mut texture_file_name=std::path::PathBuf::from("materials"); //lower case @@ -1084,7 +1085,7 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> }{ found_texture=true; let texture_name=texture_name.clone(); - s.spawn(move||{ + thread_handles.push(s.spawn(move||{ let image=vtf::from_bytes(&mut stuff)?.highres_image.decode(0)?.to_rgba8(); let format=if image.width()%4!=0||image.height()%4!=0{ @@ -1108,7 +1109,7 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?); dds.write(&mut writer)?; Ok::<(),anyhow::Error>(()) - }); + })); } } { @@ -1123,7 +1124,7 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> }{ found_texture=true; let texture_name=texture_name.clone(); - s.spawn(move||{ + thread_handles.push(s.spawn(move||{ let image=vtf::from_bytes(&mut stuff)?.highres_image.decode(0)?.to_rgba8(); let format=if image.width()%4!=0||image.height()%4!=0{ @@ -1147,13 +1148,19 @@ fn extract_textures(paths:Vec,vpk_path:std::path::PathBuf)-> let mut writer = std::io::BufWriter::new(std::fs::File::create(dest)?); dds.write(&mut writer)?; Ok::<(),anyhow::Error>(()) - }); + })); } } if !found_texture{ println!("no data"); } } + for thread in thread_handles{ + match thread.join(){ + Ok(a)=>a?, + Err(e)=>println!("error: {:?}",e), + } + } Ok::<(),anyhow::Error>(()) })? }