diff --git a/crates/formats/src/export/mod.rs b/crates/formats/src/export/mod.rs index 348e3ab8..3294ad29 100644 --- a/crates/formats/src/export/mod.rs +++ b/crates/formats/src/export/mod.rs @@ -779,6 +779,9 @@ fn plan_outputs(project: &Project, ts: usize, mesh_name: &str, opts: &ExportOpti // Bucket layers in tile order to move their names into the corresponding PSD let mut psd_layers = Vec::new(); + + // A PSD map scaled past the largest side fails only the set's PSDs, as their other planning failures do + let mut psd_too_large = None; let project_stem = project.name.replace('/', "_"); let mesh_stem = mesh_name.replace('/', "_"); let set_stem = set.name.replace('/', "_"); @@ -792,8 +795,17 @@ fn plan_outputs(project: &Project, ts: usize, mesh_name: &str, opts: &ExportOpti let own = opts.maps.get(&map_index); let (format, bit_depth, dither) = opts.map_file_type(map_index, map); let enabled = own.is_none_or(|o| o.enabled); - if enabled { - check_scaled_block(set, (block_width, block_height), opts.map_size(map_index))?; + if enabled && let Err(error) = check_scaled_block(set, (block_width, block_height), opts.map_size(map_index)) { + if format != FileFormat::Psd { + return Err(error); + } + + if psd_too_large.is_none() { + psd_too_large = Some(match error { + FormatError::Invalid(reason) => reason, + other => other.to_string(), + }); + } } let space = opts.space_for_map(map, format, bit_depth); @@ -926,6 +938,10 @@ fn plan_outputs(project: &Project, ts: usize, mesh_name: &str, opts: &ExportOpti (untiled_psd_stem(project, mesh_name, ts, set, opts.atlas), None) }; let (name, renamed) = unique_name(&mut used, &stem, ext, &mut warnings); + if let Some(reason) = &psd_too_large { + psd_failures.push((name, FormatError::Invalid(reason.clone()))); + continue; + } if let Err(error) = layered_psd::preflight(set, opts, tile, bit_depth, layers.iter(), budget.working_bytes) { psd_failures.push((name, error)); continue; diff --git a/crates/formats/src/export/tests.rs b/crates/formats/src/export/tests.rs index 8b0b1e77..bc57bfaf 100644 --- a/crates/formats/src/export/tests.rs +++ b/crates/formats/src/export/tests.rs @@ -1294,6 +1294,23 @@ fn an_export_size_that_scales_a_tall_set_past_the_largest_side_is_refused() { assert!(list_outputs(&fx.project, 0, "sphere", &options).unwrap().is_empty(), "a disabled map never allocates an image"); } +#[test] +fn a_psd_scaled_past_the_largest_side_leaves_the_sets_other_maps() { + let mut fx = Fx::new(&default_channels()); + fx.project.texture_sets[0].set_size(RES, RES * 4); + let mut options = one_map(FileFormat::Png, 8, roughness()); + let mut psd = options.preset.maps[0].clone(); + (psd.file, psd.format, psd.bit_depth, psd.channels) = ("layered".into(), FileFormat::Psd, 8, rgba_half_alpha()); + options.preset.maps.push(psd); + options.size = Some(MAX_IMAGE_SIZE / 2); + options.maps.insert(0, MapOverride { size: Some(MAX_IMAGE_SIZE / 4), ..MapOverride::default() }); + + let plan = list_outputs(&fx.project, 0, "sphere", &options).unwrap(); + + assert!(plan.len() == 1 && plan[0].format == FileFormat::Png, "{plan:?}"); + assert!(plan[0].warnings.iter().any(|warning| is_set_warning(warning)), "{:?}", plan[0].warnings); +} + #[test] fn psd_plan_rejects_a_version_one_atlas_over_its_dimension_limit() { let mut fx = Fx::new(&default_channels());