Preview: nothing is drawn once the current inputs fail (#3254) (#3256)

* claim: #3254

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Preview: nothing is drawn once the current inputs fail (#3254)

The last good preview stayed up when the current inputs made the feature
fail, so the view contradicted the dialog (Extrude at 0 mm still showed
the 1 mm extrusion beside its error). Once the result for the current
inputs is an error, the preview scene is hidden and the bodies it stood
in for come back; while the next preview computes, the last good one
still stays up as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Extrude preview: a zero distance is refused at once (#3254)

The straight extrusion feedback gave up on a zero distance, so the
preview built a whole scratch design only for the kernel to refuse it,
and the old preview hung on until then. It now returns the extrusion's
own error straight away.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Phanoob <phanoob@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-10-20 03:50:52 +00:00
1 parent fe3b14e798
commit 58303ba036
2 files changed
+46 -9

No files matched your search

+27 -1
View File
@@ -79,7 +79,7 @@ impl StraightPreview {
if direction == "negative" {
distance = -distance;
}
if !distance.is_finite() || distance.abs() < 1e-9 || distance.abs() > 1e6 {
if !distance.is_finite() || distance.abs() > 1e6 {
return None;
}
let operation = params.get("operation").and_then(Value::as_str).unwrap_or("new");
@@ -90,6 +90,11 @@ impl StraightPreview {
if inputs.is_empty() || inputs.len() > 1024 {
return None;
}
// Zero makes no extrusion. Say so now rather than building the scratch design only
// for the kernel to refuse it: that wait was a visible lag (#3254).
if distance.abs() < 1e-9 {
return Some(Err(solidcraft_engine::kernel::KernelError::Invalid("extrude distance is zero".into()).to_string()));
}
if self
.cached
.as_ref()
@@ -362,6 +367,27 @@ mod tests {
assert!(preview.compute(&h.app, &commands, colors).is_none());
}
/// #3254: a zero distance is refused at once, with the error the extrusion itself gives,
/// instead of after a full scratch preview.
#[test]
fn zero_distance_is_refused_without_a_scratch_preview() {
let mut h = Harness::new();
h.app.run("solid.box", json!({"length":4,"width":3,"height":5,"body_name":"Stock"})).unwrap();
let world = h.app.session.world_state();
let face =
world.body("Stock").unwrap().body.faces(0.001).unwrap().into_iter().find(|face| face.plane_normal.is_some_and(|n| n.z > 0.99)).unwrap();
h.app.session.selection = vec![Sel::Face { body: "Stock".into(), index: face.index, point: face.centroid }];
h.app.start("solid.extrude");
if let Kind::Extrude { distance, .. } = &mut h.app.dialog.as_mut().unwrap().kind {
*distance = "0 mm".into();
}
let commands = crate::dialogs::apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap();
let colors = Colors::from_tokens(&crate::theme::Tokens::get());
let Some(Err(error)) = StraightPreview::default().compute(&h.app, &commands, colors) else { panic!("no immediate error") };
let engine = h.app.session.preview(&commands).unwrap_err().to_string();
assert_eq!(error, engine, "the same error as the extrusion's own");
}
#[test]
fn profile_feedback_keeps_holes_and_skips_unsupported_curves() {
let mut harness = Harness::new();
+19 -8
View File
@@ -2,7 +2,8 @@
//! scratch copy of the session ([`solidcraft_engine::Session::preview`]), off the UI thread
//! where threads exist, and the result is drawn in place of the bodies it changes: new surface
//! tinted, removed material as a translucent ghost. The last good preview stays up while the
//! next one computes or when an input makes the feature fail (the error shows in the dialog).
//! next one computes; once the current inputs make the feature fail, nothing is previewed and
//! the error shows in the dialog (#3254).
//! Nothing here touches the document or the undo history.
//!
//! A feature that adds or removes a tool body (join, cut, intersect) shows only its tool. That
@@ -83,7 +84,7 @@ pub struct PreviewState {
/// Is a preview scene up?
pub active: bool,
pub sketches: Vec<SketchPreview>,
/// Why the current inputs don't make a feature (the last good preview stays up).
/// Why the current inputs don't make a feature (nothing is previewed then).
pub error: Option<String>,
/// A preview is being computed.
pub busy: bool,
@@ -114,6 +115,16 @@ impl PreviewState {
self.active && !self.rolled_back
}
/// Stop drawing the preview scene and give the bodies it stood in for back to the model.
fn hide_scene(&mut self) {
if self.active || !self.replaced.is_empty() {
self.active = false;
self.bounds = Aabb3::EMPTY;
self.replaced.clear();
self.set_scene(GpuScene::default());
}
}
fn clear(&mut self) {
self.straight.clear();
self.running = None;
@@ -127,12 +138,7 @@ impl PreviewState {
self.sketches.clear();
self.busy = false;
self.rolled_back = false;
if self.active || !self.replaced.is_empty() {
self.active = false;
self.bounds = Aabb3::EMPTY;
self.replaced.clear();
self.set_scene(GpuScene::default());
}
self.hide_scene();
}
/// Drop the preview of a design that leaves the window. Its scene goes too: the viewport
@@ -166,7 +172,10 @@ impl PreviewState {
self.tapered = b.tapered;
self.set_scene(b.scene);
}
// The current inputs make no feature: the last good geometry would contradict
// them (a 1 mm extrusion still drawn at 0 mm), so nothing is drawn.
Err(e) => {
self.hide_scene();
self.sketches.clear();
self.error = Some(e);
self.applied = None;
@@ -838,6 +847,8 @@ mod tests {
pv.poll(2, None);
assert_eq!(pv.error.as_deref(), Some("current invalid expression"));
assert_eq!(pv.shown_key, Some(2));
assert!(!pv.active && pv.replaced.is_empty(), "the current inputs failed: nothing is previewed (#3254)");
assert_ne!(pv.key, 9, "the viewport takes the empty scene");
pv.poll(2, None);
assert_eq!(pv.error.as_deref(), Some("current invalid expression"), "current errors still prevent invalid Apply");
}