Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

test: failing regression test for #268: Panic from truck-topology lib.rs:186 when joining struts that end on a bore wall (#283)

Jonas Wredef5257041923c
diff --git a/crates/engine/src/boolean_regression_tests.rs b/crates/engine/src/boolean_regression_tests.rs
index ccbb9a4b5b..20bcea1666 100644
--- a/crates/engine/src/boolean_regression_tests.rs
+++ b/crates/engine/src/boolean_regression_tests.rs
@@ -64,3 +64,27 @@ fn oblique_cut_through_a_small_arc_matches_a_split() {
assert!((got - above).abs() < 1e-6 * above, "{got} vs {above}");
}
}
+
+/// Joining struts that end on a bore wall reached a truck-topology panic (#268). The guard caught it,
+/// but no kernel call should panic at all (wasm aborts on a panic).
+#[test]
+fn struts_ending_on_a_bore_wall_join_without_a_panic() {
+ use std::sync::Arc;
+ use std::sync::atomic::{AtomicUsize, Ordering};
+ let me = std::thread::current().id();
+ let count = Arc::new(AtomicUsize::new(0));
+ let c2 = count.clone();
+ let prev = std::panic::take_hook();
+ std::panic::set_hook(Box::new(move |_| {
+ if std::thread::current().id() == me {
+ c2.fetch_add(1, Ordering::SeqCst);
+ }
+ }));
+ let mut s = Session::default();
+ let script: Value = serde_json::from_str(include_str!("../../../examples/regressions/join_struts_on_bore_wall.json")).unwrap();
+ let result = s.run_script(&script);
+ std::panic::set_hook(prev);
+ assert_eq!(count.load(Ordering::SeqCst), 0, "kernel panics during the join");
+ result.unwrap();
+ assert_eq!(s.model.state().bodies.len(), 1);
+}
diff --git a/crates/kernel/src/sew.rs b/crates/kernel/src/sew.rs
index 0d00d8c266..7c2b66929a 100644
--- a/crates/kernel/src/sew.rs
+++ b/crates/kernel/src/sew.rs
@@ -363,7 +363,8 @@ fn sew_impl(faces: &[FaceSpec], touching: bool, sources: Option<&[Option<crate::
}
for e in l {
let (a, b) = e.ends();
- if !a.is_finite() || !b.is_finite() || a.dist(b) < 1e-9 {
+ // Ends that weld to one vertex would make truck panic on a zero-length edge (#268).
+ if !a.is_finite() || !b.is_finite() || a.dist(b) < 1e-9 || key(a) == key(b) {
return Err(KernelError::Invalid("sew: a degenerate edge".into()));
}
}
diff --git a/examples/regressions/join_struts_on_bore_wall.json b/examples/regressions/join_struts_on_bore_wall.json
new file mode 100644
index 0000000000..b2ab3b52ad
--- /dev/null
+++ b/examples/regressions/join_struts_on_bore_wall.json
@@ -0,0 +1,10 @@
+{
+ "description": "A 25 x 140 x 140 fan frame with an R68 bore and two crossing 4 x 4 struts whose ends lie on the bore wall, joined into the frame. truck-topology panicked twice (lib.rs:186 'Two same vertices cannot construct an edge'); the kernel guard caught it, but the panic hook printed it. Issue #268.",
+ "commands": [
+ {"command": "solid.box", "params": {"corner": [438, 50, 42], "length": 25, "width": 140, "height": 140, "operation": "new_body", "body_name": "Frame"}},
+ {"command": "solid.cylinder", "params": {"base": [438, 120, 112], "axis": "X", "radius": 68, "height": 25, "operation": "cut"}},
+ {"command": "solid.box", "params": {"corner": [459, 52, 110], "length": 4, "width": 136, "height": 4, "operation": "new_body", "body_name": "StrutH"}},
+ {"command": "solid.box", "params": {"corner": [459, 118, 44], "length": 4, "width": 4, "height": 136, "operation": "new_body", "body_name": "StrutV"}},
+ {"command": "solid.combine", "params": {"target": "Frame", "tools": ["StrutH", "StrutV"], "operation": "join"}}
+ ]
+}