diff --git a/crates/effects/src/solids.rs b/crates/effects/src/solids.rs index e20dbdba17..52739983a5 100644 --- a/crates/effects/src/solids.rs +++ b/crates/effects/src/solids.rs @@ -1449,8 +1449,8 @@ fn meshes_for(fx: &Effect, shapes: &[Profile], total: &mut usize, limit: usize) } let (parts, bounds) = solid_parts(shapes, b); // The solids the art draws, past the limits of the object's solids together as it is - // ([`built_solids`]), each solid's faces dropped once counted. - let drawn: Vec = built_solids(&fx.id, &p, &parts, bounds, MAX_OBJECT_FACES).map(|r| r.map(|f| f.is_some())).collect::>()?; + // ([`built_solids`]), each built and its faces counted as the loop reaches it, then dropped. + let drawn = built_solids(&fx.id, &p, &parts, bounds, MAX_OBJECT_FACES).map(|r| r.map(|f| f.is_some())); // Inflate lays out every puff at once (they share one eye); each Inflate and Extrude & Bevel // solid and its mesh are built as the loop reaches them. let mut inflated = (fx.id == INFLATE).then(|| { @@ -1460,7 +1460,7 @@ fn meshes_for(fx: &Effect, shapes: &[Profile], total: &mut usize, limit: usize) let extrude = if fx.id == CLASSIC_EXTRUDE { classic_extrude_options(&p) } else { extrude_options(&p) }; for ((item, member, area, rule, _, _), drawn) in parts.iter().zip(drawn) { let item: &AppearanceItem = item; - if !drawn { + if !drawn? { // A stroke the art leaves out is left out of the meshes too; Inflate's next puff // still belongs to the next part. if let Some(built) = inflated.as_mut() { diff --git a/crates/effects/src/solids/tests_mesh.rs b/crates/effects/src/solids/tests_mesh.rs index d0e192f550..aeefafbc77 100644 --- a/crates/effects/src/solids/tests_mesh.rs +++ b/crates/effects/src/solids/tests_mesh.rs @@ -59,6 +59,20 @@ fn the_meshes_of_one_object_share_one_triangle_budget() { assert!(meshes_for(effect, &shapes, &mut total, MAX_MESH_TRIANGLES).is_err_and(|e| e.contains("too complex"))); } +/// A mesh past the budget stops the export before the solids after it are built. +#[test] +fn the_solids_after_a_mesh_past_the_budget_are_not_built() { + let mut n = square_node(1, 100.0); + n.appearance.effects.push(fx(EXTRUDE, json!({}))); + let first = three_d_meshes(&n).unwrap()[0].mesh.triangles.len(); + let shapes = [Profile { path: profile(&n).unwrap().0, rule: FillRule::NonZero, items: solid_paints(&n), opacity: 1.0, scopes: vec![] }]; + let Some(effect) = n.appearance.effects.first() else { panic!("no effect") }; + let mut total = MAX_MESH_TRIANGLES - first + 1; + SOLIDS_BUILT.with(|b| b.set(0)); + assert!(meshes_for(effect, &shapes, &mut total, MAX_MESH_TRIANGLES).is_err_and(|e| e.contains("too complex"))); + assert_eq!(SOLIDS_BUILT.with(std::cell::Cell::get), 1, "the stroke's solid is never built"); +} + #[test] fn revolve_stops_at_the_first_mesh_past_the_budget() { // The fill revolves into a mesh; the stroke's profile, copied 1000 times, is too complex to