| author | |
| committer | |
| log | 4bfee714f3fecab65dbb6919de5f1d8b6272452b |
| tree | f955389766d04b281b9c1b7febfe20951dcc5843 |
| parent | 4c8a96761128f8e16c9e38ea6f9d0a5f8f3b026c |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
21 files changed, 887 insertions(+), 173 deletions(-)
crates/app/src/inspector/catalog.rs+35-7| ... | ... | @@ -101,13 +101,14 @@ fn parse_input(v: &Value) -> Option<InputDef> { |
| 101 | 101 | .unwrap_or_default(); |
| 102 | 102 | let control = control_for(v["input_control"].as_str()?, data_type, !entries.is_empty())?; |
| 103 | 103 | let num = |key: &str| v[key].as_f64(); |
| 104 | let mut scale = [num("min_scale").unwrap_or(0.0), num("max_scale").unwrap_or(1.0)]; | |
| 105 | if scale[1] <= scale[0] { | |
| 106 | scale[1] = scale[0] + 1.0; | |
| 107 | } | |
| 104 | let scale = sanitize_scale(num("min_scale"), num("max_scale")); | |
| 105 | let allowed = sanitize_allowed(num("min_allowed"), num("max_allowed")); | |
| 108 | 106 | let default = match &v["default"] { |
| 109 | Value::Array(a) => [a.first().and_then(Value::as_f64).unwrap_or(0.5), a.get(1).and_then(Value::as_f64).unwrap_or(0.5)], | |
| 110 | d => [d.as_f64().unwrap_or(0.0), 0.0], | |
| 107 | Value::Array(a) => [ | |
| 108 | finite_or(a.first().and_then(Value::as_f64), 0.5), | |
| 109 | finite_or(a.get(1).and_then(Value::as_f64), 0.5), | |
| 110 | ], | |
| 111 | d => [finite_or(d.as_f64(), 0.0), 0.0], | |
| 111 | 112 | }; |
| 112 | 113 | let name = v["name"].as_str().map_or_else(|| humanize(id), str::to_owned); |
| 113 | 114 | Some(InputDef { |
| ... | ... | @@ -115,7 +116,7 @@ fn parse_input(v: &Value) -> Option<InputDef> { |
| 115 | 116 | default, |
| 116 | 117 | default_text: v["default"].as_str().unwrap_or_default().to_owned(), |
| 117 | 118 | scale, |
| 118 | allowed: [num("min_allowed"), num("max_allowed")], | |
| 119 | allowed, | |
| 119 | 120 | integer: v["integer"].as_bool().unwrap_or(false), |
| 120 | 121 | page: v["page"].as_str().map(str::to_owned), |
| 121 | 122 | entries, |
| ... | ... | @@ -124,6 +125,33 @@ fn parse_input(v: &Value) -> Option<InputDef> { |
| 124 | 125 | }) |
| 125 | 126 | } |
| 126 | 127 | |
| 128 | pub(super) fn finite_or(v: Option<f64>, fallback: f64) -> f64 { | |
| 129 | v.filter(|n| n.is_finite()).unwrap_or(fallback) | |
| 130 | } | |
| 131 | ||
| 132 | pub(super) fn sanitize_scale(min: Option<f64>, max: Option<f64>) -> [f64; 2] { | |
| 133 | let lo = finite_or(min, 0.0); | |
| 134 | let hi = finite_or(max, lo + 1.0); | |
| 135 | if !lo.is_finite() || !hi.is_finite() { | |
| 136 | return [0.0, 1.0]; | |
| 137 | } | |
| 138 | if hi <= lo { | |
| 139 | let next = lo + 1.0; | |
| 140 | if next.is_finite() && next > lo { [lo, next] } else { [0.0, 1.0] } | |
| 141 | } else { | |
| 142 | [lo, hi] | |
| 143 | } | |
| 144 | } | |
| 145 | ||
| 146 | pub(super) fn sanitize_allowed(min: Option<f64>, max: Option<f64>) -> [Option<f64>; 2] { | |
| 147 | let lo = min.filter(|v| v.is_finite()); | |
| 148 | let hi = max.filter(|v| v.is_finite()); | |
| 149 | match (lo, hi) { | |
| 150 | (Some(a), Some(b)) if a > b => [Some(b), Some(a)], | |
| 151 | other => [other.0, other.1], | |
| 152 | } | |
| 153 | } | |
| 154 | ||
| 127 | 155 | /// Maps a Fusion control to an editable one; `None` hides inputs with no editor (images, masks, curves). |
| 128 | 156 | pub(super) fn control_for(name: &str, data_type: &str, has_entries: bool) -> Option<Control> { |
| 129 | 157 | match (name, data_type) { |
crates/app/src/inspector/controls.rs+3-1| ... | ... | @@ -286,7 +286,9 @@ fn choice_index(cx: &Cx, def: &ControlDef) -> usize { |
| 286 | 286 | fn write_choice(cx: &mut Cx, def: &ControlDef, index: usize) { |
| 287 | 287 | let ch = &def.channels[0]; |
| 288 | 288 | if def.fuid { |
| 289 | cx.write_value(&def.label, &ch.id, ParamValue::FuId(def.entries[index].clone())); | |
| 289 | if let Some(entry) = def.entries.get(index) { | |
| 290 | cx.write_value(&def.label, &ch.id, ParamValue::FuId(entry.clone())); | |
| 291 | } | |
| 290 | 292 | } else { |
| 291 | 293 | cx.write_numbers(&def.label, &[(ch, index as f64)], None); |
| 292 | 294 | } |
crates/app/src/inspector/dynamic.rs+10-9| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | //! Inputs the catalog cannot describe: a node's own `UserControls`, tools Fusion's introspection |
| 2 | 2 | //! skipped (curated schemas), and live inputs no row covers. |
| 3 | 3 | |
| 4 | use super::catalog::{Control, InputDef, control_for, humanize}; | |
| 4 | use super::catalog::{Control, InputDef, control_for, finite_or, humanize, sanitize_allowed, sanitize_scale}; | |
| 5 | 5 | use super::layout::{ToolLayout, build_layout}; |
| 6 | 6 | use super::schemas::{ParamKind, infer_float_range, schema_for_kind}; |
| 7 | 7 | use model::{Comp, LuaKey, LuaTable, NodeId, ParamValue}; |
| ... | ... | @@ -35,25 +35,26 @@ fn user_def(id: &str, t: &LuaTable) -> Option<InputDef> { |
| 35 | 35 | _ => "SliderControl", |
| 36 | 36 | }); |
| 37 | 37 | let control = control_for(control_name, data_type, !entries.is_empty())?; |
| 38 | let mut scale = [t.get_f64("INP_MinScale").unwrap_or(0.0), t.get_f64("INP_MaxScale").unwrap_or(1.0)]; | |
| 39 | if scale[1] <= scale[0] { | |
| 40 | scale[1] = scale[0] + 1.0; | |
| 41 | } | |
| 38 | let scale = sanitize_scale(t.get_f64("INP_MinScale"), t.get_f64("INP_MaxScale")); | |
| 39 | let allowed = sanitize_allowed(t.get_f64("INP_MinAllowed"), t.get_f64("INP_MaxAllowed")); | |
| 42 | 40 | let name = t.get_str("LINKS_Name").map_or_else(|| humanize(id), str::to_owned); |
| 43 | 41 | Some(InputDef { |
| 44 | 42 | fuid: matches!(data_type, "FuID" | "Text"), |
| 45 | 43 | default: if data_type == "Point" { |
| 46 | [t.get_f64("INP_DefaultX").unwrap_or(0.5), t.get_f64("INP_DefaultY").unwrap_or(0.5)] | |
| 44 | [finite_or(t.get_f64("INP_DefaultX"), 0.5), finite_or(t.get_f64("INP_DefaultY"), 0.5)] | |
| 47 | 45 | } else { |
| 48 | [t.get_f64("INP_Default").unwrap_or(0.0), 0.0] | |
| 46 | [finite_or(t.get_f64("INP_Default"), 0.0), 0.0] | |
| 49 | 47 | }, |
| 50 | 48 | default_text: t.get_str("INP_Default").unwrap_or_default().to_owned(), |
| 51 | 49 | scale, |
| 52 | allowed: [t.get_f64("INP_MinAllowed"), t.get_f64("INP_MaxAllowed")], | |
| 50 | allowed, | |
| 53 | 51 | integer: t.get_bool("INP_Integer").unwrap_or(false), |
| 54 | 52 | page: Some(t.get_str("ICS_ControlPage").unwrap_or("User").to_owned()), |
| 55 | 53 | entries, |
| 56 | group: t.get_f64("IC_ControlGroup").map(|g| (g as i64, t.get_f64("IC_ControlID").unwrap_or(0.0) as u32)), | |
| 54 | group: t.get_f64("IC_ControlGroup").filter(|g| g.is_finite()).map(|g| { | |
| 55 | let cid = t.get_f64("IC_ControlID").filter(|v| v.is_finite() && *v >= 0.0).unwrap_or(0.0); | |
| 56 | (g as i64, cid.min(f64::from(u32::MAX)) as u32) | |
| 57 | }), | |
| 57 | 58 | ..InputDef::new(id, &name, control) |
| 58 | 59 | }) |
| 59 | 60 | } |
crates/app/src/inspector/edit.rs+10-2| ... | ... | @@ -92,7 +92,12 @@ impl Cx<'_> { |
| 92 | 92 | self.history.push_snapshot(self.comp, format!("Set {label}")); |
| 93 | 93 | } |
| 94 | 94 | for &(ch, value) in edits { |
| 95 | let value = value.clamp(ch.allowed[0].unwrap_or(f64::MIN), ch.allowed[1].unwrap_or(f64::MAX)); | |
| 95 | if !value.is_finite() { | |
| 96 | continue; | |
| 97 | } | |
| 98 | let lo = ch.allowed[0].filter(|v| v.is_finite()).unwrap_or(f64::MIN); | |
| 99 | let hi = ch.allowed[1].filter(|v| v.is_finite()).unwrap_or(f64::MAX); | |
| 100 | let value = if lo <= hi { value.clamp(lo, hi) } else { value }; | |
| 96 | 101 | let animated = keyframe_state(self.comp, self.node, &ch.id, self.frame) != KeyframeState::Static; |
| 97 | 102 | if animated { |
| 98 | 103 | let _ = self.comp.set_keyframe(self.node, &ch.id, self.frame, value); |
| ... | ... | @@ -169,7 +174,10 @@ impl Cx<'_> { |
| 169 | 174 | Kind::Point => ParamValue::Point(ch.default), |
| 170 | 175 | Kind::Text if def.fuid => ParamValue::FuId(def.default_text.clone()), |
| 171 | 176 | Kind::Text => ParamValue::Text(def.default_text.clone()), |
| 172 | Kind::Segmented | Kind::Combo if def.fuid => ParamValue::FuId(def.entries[def.default_index].clone()), | |
| 177 | Kind::Segmented | Kind::Combo if def.fuid => { | |
| 178 | let s = def.entries.get(def.default_index).cloned().unwrap_or_else(|| def.default_text.clone()); | |
| 179 | ParamValue::FuId(s) | |
| 180 | } | |
| 173 | 181 | _ => ParamValue::Number(self.default_of(ch)), |
| 174 | 182 | }; |
| 175 | 183 | if current != default { |
crates/app/src/inspector/layout.rs+2-1| ... | ... | @@ -140,9 +140,10 @@ fn sections(kind: &str, first_title: &str, controls: Vec<ControlDef>) -> Vec<Sec |
| 140 | 140 | fn group_len(defs: &[InputDef], i: usize) -> usize { |
| 141 | 141 | let head = &defs[i]; |
| 142 | 142 | let Some((group, first)) = head.group else { return 1 }; |
| 143 | let Some(next) = first.checked_add(1) else { return 1 }; | |
| 143 | 144 | 1 + defs[i + 1..] |
| 144 | 145 | .iter() |
| 145 | .zip(first + 1..) | |
| 146 | .zip(next..) | |
| 146 | 147 | .take_while(|(d, id)| d.control == head.control && d.group == Some((group, *id))) |
| 147 | 148 | .count() |
| 148 | 149 | } |
crates/app/src/inspector/tests.rs+58| ... | ... | @@ -521,4 +521,62 @@ mod catalog_layout { |
| 521 | 521 | h.frame(16); |
| 522 | 522 | assert_ne!(key(&h), before); |
| 523 | 523 | } |
| 524 | ||
| 525 | #[test] | |
| 526 | fn malformed_user_controls_extreme_bounds_and_stale_node_do_not_panic() { | |
| 527 | let mut comp = Comp::from_fusion_str( | |
| 528 | r#"Composition { | |
| 529 | Tools = ordered() { | |
| 530 | Mac = MacroOperator { | |
| 531 | UserControls = ordered() { | |
| 532 | BadClamp = { LINKID_DataType = "Number", INPID_InputControl = "SliderControl", INP_MinScale = 10, INP_MaxScale = 2, INP_MinAllowed = 5, INP_MaxAllowed = 1 }, | |
| 533 | OverflowGroup = { LINKID_DataType = "Number", INPID_InputControl = "RangeControl", IC_ControlGroup = 1, IC_ControlID = 4294967295 }, | |
| 534 | BadDefault = { LINKID_DataType = "Number", INPID_InputControl = "ComboControl", INP_Default = 99, { CCS_AddString = "OnlyOne" } }, | |
| 535 | }, | |
| 536 | }, | |
| 537 | }, | |
| 538 | }"#, | |
| 539 | ) | |
| 540 | .expect("comp"); | |
| 541 | let mac = comp.find_node("Mac").unwrap(); | |
| 542 | comp.set_input_value(mac, "BadClamp", model::ParamValue::Number(f64::NAN)); | |
| 543 | ||
| 544 | let theme = ui::Theme::dark(); | |
| 545 | let mut state = InspectorState::new(&theme); | |
| 546 | let mut ui = ui::Ui::new(theme); | |
| 547 | let _ = ui.measure("M"); | |
| 548 | let (mut history, stats) = (CompHistory::default(), engine::EvalStats::default()); | |
| 549 | ui.begin([360.0, 900.0], 1.0, Instant::now()); | |
| 550 | state.build_ui(&mut ui, ui::Id::ROOT.child("pane"), &mut comp, &mut history, Some(mac), 0.0, &stats); | |
| 551 | ui.end(); | |
| 552 | ||
| 553 | // Direct edit with inverted allowed bounds and NaN must not panic. | |
| 554 | let mut actions = Vec::new(); | |
| 555 | let mut edit = super::super::edit::EditState::default(); | |
| 556 | let mut cx = super::super::edit::Cx { | |
| 557 | comp: &mut comp, | |
| 558 | history: &mut history, | |
| 559 | actions: &mut actions, | |
| 560 | node: mac, | |
| 561 | frame: 0.0, | |
| 562 | now: Instant::now(), | |
| 563 | p: state.palette, | |
| 564 | expr: &state.expr, | |
| 565 | edit: &mut edit, | |
| 566 | }; | |
| 567 | let bad_ch = super::super::layout::Channel { | |
| 568 | id: "BadClamp".to_owned(), | |
| 569 | default: [0.0, 0.0], | |
| 570 | scale: [0.0, 1.0], | |
| 571 | allowed: [Some(5.0), Some(1.0)], | |
| 572 | integer: false, | |
| 573 | }; | |
| 574 | cx.write_numbers("BadClamp", &[(&bad_ch, 3.0), (&bad_ch, f64::NAN)], None); | |
| 575 | ||
| 576 | // Stale NodeId falls back to empty state cleanly. | |
| 577 | ui.begin([360.0, 900.0], 1.0, Instant::now()); | |
| 578 | state.build_ui(&mut ui, ui::Id::ROOT.child("pane"), &mut comp, &mut history, Some(model::NodeId(99)), 0.0, &stats); | |
| 579 | ui.end(); | |
| 580 | assert_eq!(super::super::keyframe_state(&comp, model::NodeId(99), "Size", 0.0), super::super::KeyframeState::Static); | |
| 581 | } | |
| 524 | 582 | } |
crates/app/src/inspector/widgets.rs+3-3| ... | ... | @@ -14,9 +14,9 @@ pub enum KeyframeState { |
| 14 | 14 | /// Computes whether an input is static, animated on another frame, or has a keyframe at `frame`. |
| 15 | 15 | pub fn keyframe_state(comp: &Comp, node_id: NodeId, input_name: &str, frame: f64) -> KeyframeState { |
| 16 | 16 | let Some(sp_name) = comp |
| 17 | .node(node_id) | |
| 18 | .inputs | |
| 19 | .get(input_name) | |
| 17 | .nodes | |
| 18 | .get(node_id.0) | |
| 19 | .and_then(|n| n.inputs.get(input_name)) | |
| 20 | 20 | .and_then(|b| b.source_op.as_deref()) |
| 21 | 21 | else { |
| 22 | 22 | return KeyframeState::Static; |
crates/app/src/keyframes.rs+91-5| ... | ... | @@ -164,19 +164,36 @@ impl KeyframesView { |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | pub fn resize(&mut self, size: [f32; 2]) { |
| 167 | self.size = [size[0].max(1.0), size[1].max(1.0)]; | |
| 167 | self.size = [ | |
| 168 | if size[0].is_finite() { size[0].max(1.0) } else { 1.0 }, | |
| 169 | if size[1].is_finite() { size[1].max(1.0) } else { 1.0 }, | |
| 170 | ]; | |
| 168 | 171 | } |
| 169 | 172 | |
| 170 | 173 | pub fn fit_comp(&mut self, comp: &Comp) { |
| 171 | 174 | let r0 = comp.render_range[0] as f64; |
| 172 | let r1 = comp.render_range[1].max(comp.render_range[0] + 10) as f64; | |
| 175 | let r1 = comp.render_range[1].max(comp.render_range[0].saturating_add(10)) as f64; | |
| 173 | 176 | let pad = ((r1 - r0) * 0.04).max(4.0); |
| 174 | self.t_range = [r0 - pad, r1 + pad]; | |
| 177 | self.t_range = sanitize_t_range([r0 - pad, r1 + pad]); | |
| 175 | 178 | self.fitted = true; |
| 176 | 179 | } |
| 177 | 180 | |
| 178 | /// Drops node ids and key refs that no longer exist after undo, redo, delete, or reload. | |
| 179 | pub fn sanitize_ids(&mut self, comp: &Comp) { | |
| 181 | fn sanitize_view(&mut self) { | |
| 182 | self.resize(self.size); | |
| 183 | self.t_range = sanitize_t_range(self.t_range); | |
| 184 | if !self.scroll_y.is_finite() || self.scroll_y < 0.0 { | |
| 185 | self.scroll_y = 0.0; | |
| 186 | } | |
| 187 | if !self.pointer_local[0].is_finite() { | |
| 188 | self.pointer_local[0] = 0.0; | |
| 189 | } | |
| 190 | if !self.pointer_local[1].is_finite() { | |
| 191 | self.pointer_local[1] = 0.0; | |
| 192 | } | |
| 193 | } | |
| 194 | ||
| 195 | fn sanitize_stale(&mut self, comp: &Comp) { | |
| 196 | self.sanitize_view(); | |
| 180 | 197 | let before = self.collapsed_nodes.len(); |
| 181 | 198 | self.collapsed_nodes.retain(|id| id.0 < comp.nodes.len()); |
| 182 | 199 | if self.collapsed_nodes.len() != before { |
| ... | ... | @@ -185,12 +202,30 @@ impl KeyframesView { |
| 185 | 202 | } |
| 186 | 203 | self.selected_keys |
| 187 | 204 | .retain(|k| comp.splines.get(&k.spline).is_some_and(|sp| k.key_idx < sp.keyframes.len())); |
| 205 | if self.hovered_key.as_ref().is_some_and(|k| { | |
| 206 | comp.splines.get(&k.spline).is_none_or(|sp| k.key_idx >= sp.keyframes.len()) | |
| 207 | }) { | |
| 208 | self.hovered_key = None; | |
| 209 | } | |
| 210 | if self.retime_drag.as_ref().is_some_and(|d| { | |
| 211 | d.saved_splines.iter().any(|(sname, orig)| { | |
| 212 | comp.splines.get(sname).is_none_or(|sp| sp.keyframes.len() != orig.len()) | |
| 213 | }) | |
| 214 | }) { | |
| 215 | self.retime_drag = None; | |
| 216 | } | |
| 217 | } | |
| 218 | ||
| 219 | /// Drops node ids and key refs that no longer exist after undo, redo, delete, or reload. | |
| 220 | pub fn sanitize_ids(&mut self, comp: &Comp) { | |
| 221 | self.sanitize_stale(comp); | |
| 188 | 222 | self.hovered_key = None; |
| 189 | 223 | self.retime_drag = None; |
| 190 | 224 | self.box_select = None; |
| 191 | 225 | } |
| 192 | 226 | |
| 193 | 227 | pub fn sync_tracks(&mut self, comp: &Comp, selected_node: Option<NodeId>) { |
| 228 | self.sanitize_stale(comp); | |
| 194 | 229 | if !self.fitted { |
| 195 | 230 | self.fit_comp(comp); |
| 196 | 231 | } |
| ... | ... | @@ -385,6 +420,7 @@ impl KeyframesView { |
| 385 | 420 | ) -> Vec<KeyframesAction> { |
| 386 | 421 | let mut actions = Vec::new(); |
| 387 | 422 | self.pointer_local = [pointer_window[0] - rect[0], pointer_window[1] - rect[1]]; |
| 423 | self.sync_tracks(comp, selected_node); | |
| 388 | 424 | let plot = self.plot_rect(); |
| 389 | 425 | |
| 390 | 426 | match event { |
| ... | ... | @@ -572,6 +608,20 @@ impl KeyframesView { |
| 572 | 608 | } |
| 573 | 609 | } |
| 574 | 610 | |
| 611 | fn sanitize_t_range(r: [f64; 2]) -> [f64; 2] { | |
| 612 | if !r[0].is_finite() || !r[1].is_finite() || r[0] >= r[1] || !(r[1] - r[0]).is_finite() { | |
| 613 | return [0.0, 200.0]; | |
| 614 | } | |
| 615 | if r[1] - r[0] < 1e-3 { | |
| 616 | let mid = 0.5 * (r[0] + r[1]); | |
| 617 | if (mid - 0.5).is_finite() && (mid + 0.5).is_finite() { | |
| 618 | return [mid - 0.5, mid + 0.5]; | |
| 619 | } | |
| 620 | return [0.0, 200.0]; | |
| 621 | } | |
| 622 | r | |
| 623 | } | |
| 624 | ||
| 575 | 625 | pub fn build_tracks( |
| 576 | 626 | comp: &Comp, |
| 577 | 627 | selected_node: Option<NodeId>, |
| ... | ... | @@ -979,4 +1029,40 @@ mod tests { |
| 979 | 1029 | total_prims / frames |
| 980 | 1030 | ); |
| 981 | 1031 | } |
| 1032 | ||
| 1033 | #[test] | |
| 1034 | fn stale_retime_drag_empty_spline_zero_viewport_and_extreme_ranges_do_not_panic() { | |
| 1035 | let comp = sample_animated_comp(); | |
| 1036 | let mut history = CompHistory::new(); | |
| 1037 | let mut view = KeyframesView::new(&ui::Theme::dark()); | |
| 1038 | view.sync_tracks(&comp, None); | |
| 1039 | view.selected_keys.insert(DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 0 }); | |
| 1040 | view.begin_retime_drag(&comp); | |
| 1041 | assert!(view.retime_drag.is_some()); | |
| 1042 | ||
| 1043 | // Replace comp mid-retime drag with an empty comp + 0-keyframe spline. | |
| 1044 | let mut empty = Comp::from_fusion_str("Composition {}").expect("empty"); | |
| 1045 | empty.splines.insert("Empty".to_owned(), model::BezierSpline { | |
| 1046 | name: "Empty".to_owned(), | |
| 1047 | color: [200, 200, 200], | |
| 1048 | keyframes: Vec::new(), | |
| 1049 | }); | |
| 1050 | view.resize([0.0, 0.0]); | |
| 1051 | view.t_range = [200.0, 0.0]; // inverted | |
| 1052 | view.input( | |
| 1053 | &mut empty, | |
| 1054 | &mut history, | |
| 1055 | Some(NodeId(99)), | |
| 1056 | ui::Event::PointerMoved([220.0, 40.0]), | |
| 1057 | [0.0, 0.0, 0.0, 0.0], | |
| 1058 | [220.0, 40.0], | |
| 1059 | ModifiersState::empty(), | |
| 1060 | ); | |
| 1061 | assert!(view.retime_drag.is_none()); | |
| 1062 | assert!(view.t_range[0] < view.t_range[1]); | |
| 1063 | ||
| 1064 | view.t_range = [-1e308, 1e308]; | |
| 1065 | view.prepare_labels(); | |
| 1066 | let _ = view.paint(&empty, f64::NAN); | |
| 1067 | } | |
| 982 | 1068 | } |
crates/app/src/keyframes/paint.rs+51-31| ... | ... | @@ -4,6 +4,7 @@ use super::*; |
| 4 | 4 | |
| 5 | 5 | impl KeyframesView { |
| 6 | 6 | pub fn prepare_labels(&mut self) { |
| 7 | self.sanitize_view(); | |
| 7 | 8 | let cap = TEXT_CACHE_CAP.max(self.rows.len() * 2 + 128); |
| 8 | 9 | if self.text_cache.len() > cap { |
| 9 | 10 | self.text_cache.clear(); |
| ... | ... | @@ -67,18 +68,18 @@ impl KeyframesView { |
| 67 | 68 | |
| 68 | 69 | let plot = self.plot_rect(); |
| 69 | 70 | let max_ticks = f64::from(((plot[2] - plot[0]) / 56.0).max(2.0)); |
| 70 | let t_step = nice_step((self.t_range[1] - self.t_range[0]) / max_ticks); | |
| 71 | let t_start = (self.t_range[0] / t_step).floor() as i64; | |
| 72 | let t_end = (self.t_range[1] / t_step).ceil() as i64; | |
| 73 | for ti in t_start..=t_end { | |
| 74 | let key = format!("t:{}", (ti as f64 * t_step).round() as i64); | |
| 75 | self.text_cache.entry(key.clone()).or_insert_with(|| make(&key[2..], &font_sm)); | |
| 71 | if let Some((t_step, t_start, t_end)) = grid_ticks(self.t_range, max_ticks) { | |
| 72 | for ti in t_start..=t_end { | |
| 73 | let key = format!("t:{}", (ti as f64 * t_step).round() as i64); | |
| 74 | self.text_cache.entry(key.clone()).or_insert_with(|| make(&key[2..], &font_sm)); | |
| 75 | } | |
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | pub fn paint<'a>(&'a self, comp: &'a Comp, current_frame: f64) -> Vec<Primitive<'a>> { |
| 80 | 80 | let mut out = Vec::with_capacity(512); |
| 81 | let [w, h] = self.size; | |
| 81 | let w = if self.size[0].is_finite() { self.size[0].max(1.0) } else { 1.0 }; | |
| 82 | let h = if self.size[1].is_finite() { self.size[1].max(1.0) } else { 1.0 }; | |
| 82 | 83 | let plot = self.plot_rect(); |
| 83 | 84 | let top = self.tracks_top(); |
| 84 | 85 | |
| ... | ... | @@ -126,24 +127,23 @@ impl KeyframesView { |
| 126 | 127 | |
| 127 | 128 | // Ruler frame ticks |
| 128 | 129 | let max_ticks = f64::from(((plot[2] - plot[0]) / 56.0).max(2.0)); |
| 129 | let t_step = nice_step((self.t_range[1] - self.t_range[0]) / max_ticks); | |
| 130 | let t_start = (self.t_range[0] / t_step).floor() as i64; | |
| 131 | let t_end = (self.t_range[1] / t_step).ceil() as i64; | |
| 132 | for ti in t_start..=t_end { | |
| 133 | let t = ti as f64 * t_step; | |
| 134 | let x = self.time_to_x(t); | |
| 135 | if x < plot[0] || x > plot[2] { | |
| 136 | continue; | |
| 137 | } | |
| 138 | out.push(Primitive::Segment { from: [x, RULER_H], to: [x, plot[3]], width: 1.0, color: self.palette.grid }); | |
| 139 | let key = format!("t:{}", t.round() as i64); | |
| 140 | if let Some(tl) = self.text_cache.get(&key) { | |
| 141 | out.push(Primitive::Text { | |
| 142 | text: tl as &dyn Glyphs, | |
| 143 | origin: [x + 3.0, 5.0], | |
| 144 | clip: Some([plot[0], 0.0, plot[2], RULER_H]), | |
| 145 | ink: self.palette.text_dim, | |
| 146 | }); | |
| 130 | if let Some((t_step, t_start, t_end)) = grid_ticks(self.t_range, max_ticks) { | |
| 131 | for ti in t_start..=t_end { | |
| 132 | let t = ti as f64 * t_step; | |
| 133 | let x = self.time_to_x(t); | |
| 134 | if x < plot[0] || x > plot[2] { | |
| 135 | continue; | |
| 136 | } | |
| 137 | out.push(Primitive::Segment { from: [x, RULER_H], to: [x, plot[3]], width: 1.0, color: self.palette.grid }); | |
| 138 | let key = format!("t:{}", t.round() as i64); | |
| 139 | if let Some(tl) = self.text_cache.get(&key) { | |
| 140 | out.push(Primitive::Text { | |
| 141 | text: tl as &dyn Glyphs, | |
| 142 | origin: [x + 3.0, 5.0], | |
| 143 | clip: Some([plot[0], 0.0, plot[2], RULER_H]), | |
| 144 | ink: self.palette.text_dim, | |
| 145 | }); | |
| 146 | } | |
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | |
| ... | ... | @@ -178,17 +178,19 @@ impl KeyframesView { |
| 178 | 178 | let max_half = AUDIO_ROW_H * 0.42; |
| 179 | 179 | let a0 = self.audio_range[0]; |
| 180 | 180 | let n = self.audio_peaks.len() as i64; |
| 181 | let f_vis0 = (self.t_range[0].floor() as i64).max(a0); | |
| 182 | let f_vis1 = (self.t_range[1].ceil() as i64).min(a0 + n - 1); | |
| 183 | let bar_step = ((plot[2] - plot[0]) / ((self.t_range[1] - self.t_range[0]).max(1.0) as f32)).max(1.5); | |
| 181 | let [tr0, tr1] = sanitize_t_range(self.t_range); | |
| 182 | let f_vis0 = (tr0.floor() as i64).max(a0); | |
| 183 | let f_vis1 = (tr1.ceil() as i64).min(a0.saturating_add(n - 1)); | |
| 184 | let bar_step = ((plot[2] - plot[0]) / ((tr1 - tr0).max(1.0) as f32)).max(1.5); | |
| 184 | 185 | let stride = ((1.8 / bar_step).ceil() as i64).max(1); |
| 185 | 186 | let mut f = f_vis0; |
| 186 | 187 | while f <= f_vis1 { |
| 187 | 188 | let mut peak = 0.0_f32; |
| 188 | 189 | for off in 0..stride { |
| 189 | let idx = (f + off - a0) as usize; | |
| 190 | if let Some(&v) = self.audio_peaks.get(idx) { | |
| 191 | if v > peak { peak = v; } | |
| 190 | if let Some(idx) = f.saturating_add(off).checked_sub(a0).and_then(|d| usize::try_from(d).ok()) { | |
| 191 | if let Some(&v) = self.audio_peaks.get(idx) { | |
| 192 | if v > peak { peak = v; } | |
| 193 | } | |
| 192 | 194 | } |
| 193 | 195 | } |
| 194 | 196 | if peak > 0.01 { |
| ... | ... | @@ -376,7 +378,25 @@ impl KeyframesView { |
| 376 | 378 | } |
| 377 | 379 | } |
| 378 | 380 | |
| 381 | fn grid_ticks(range: [f64; 2], divs: f64) -> Option<(f64, i64, i64)> { | |
| 382 | let [lo, hi] = sanitize_t_range(range); | |
| 383 | let span = hi - lo; | |
| 384 | if !span.is_finite() || span <= 0.0 { | |
| 385 | return None; | |
| 386 | } | |
| 387 | let step = nice_step(span / divs); | |
| 388 | if !step.is_finite() || step <= 0.0 { | |
| 389 | return None; | |
| 390 | } | |
| 391 | let start = (lo / step).floor() as i64; | |
| 392 | let end = (hi / step).ceil() as i64; | |
| 393 | (end.saturating_sub(start) <= 256).then_some((step, start, end)) | |
| 394 | } | |
| 395 | ||
| 379 | 396 | fn nice_step(raw: f64) -> f64 { |
| 397 | if !raw.is_finite() { | |
| 398 | return 1.0; | |
| 399 | } | |
| 380 | 400 | let raw = raw.max(1.0); |
| 381 | 401 | let pow = 10.0_f64.powf(raw.log10().floor()); |
| 382 | 402 | let frac = raw / pow; |
crates/app/src/main.rs+25-1| ... | ... | @@ -882,7 +882,7 @@ impl Studio { |
| 882 | 882 | } |
| 883 | 883 | } |
| 884 | 884 | } |
| 885 | KeyframesAction::SelectNode(id) => { | |
| 885 | KeyframesAction::SelectNode(id) if id.0 < self.comp.nodes.len() => { | |
| 886 | 886 | // Dope sheet tracks are root-level nodes; the canvas must show the one it selects. |
| 887 | 887 | if !self.flow.scope_path().is_empty() { |
| 888 | 888 | self.flow.exit_to_depth(&self.comp, 0); |
| ... | ... | @@ -892,6 +892,7 @@ impl Studio { |
| 892 | 892 | self.flow.primary = Some(id); |
| 893 | 893 | self.spline.set_target_node(&self.comp, Some(id)); |
| 894 | 894 | } |
| 895 | KeyframesAction::SelectNode(_) => {} | |
| 895 | 896 | KeyframesAction::KeyframesEdited => { |
| 896 | 897 | self.spline.refresh_for_comp(&self.comp, self.flow.primary, false); |
| 897 | 898 | self.invalidate_node(None); |
| ... | ... | @@ -1574,4 +1575,27 @@ mod tests { |
| 1574 | 1575 | studio.sync_ram_ranges_and_prefetch(); |
| 1575 | 1576 | assert!(studio.last_prefetch_sig.is_some()); |
| 1576 | 1577 | } |
| 1578 | ||
| 1579 | #[test] | |
| 1580 | fn flow_toolbar_breadcrumbs_ignore_deleted_group_node_id() { | |
| 1581 | let comp = Comp::from_fusion_str("Composition {}").expect("empty comp"); | |
| 1582 | let mut ui = ui::Ui::new(ui::Theme::dark()); | |
| 1583 | let _ = ui.measure("M"); | |
| 1584 | ui.begin([800.0, 200.0], 1.0, Instant::now()); | |
| 1585 | let mut renaming = None; | |
| 1586 | let mut buf = String::new(); | |
| 1587 | let mut needs_focus = false; | |
| 1588 | let _ = build_flow_toolbar( | |
| 1589 | &mut ui, | |
| 1590 | &comp, | |
| 1591 | &[NodeId(99)], | |
| 1592 | false, | |
| 1593 | false, | |
| 1594 | false, | |
| 1595 | &mut renaming, | |
| 1596 | &mut buf, | |
| 1597 | &mut needs_focus, | |
| 1598 | ); | |
| 1599 | ui.end(); | |
| 1600 | } | |
| 1577 | 1601 | } |
crates/app/src/menus.rs+4-1| ... | ... | @@ -144,9 +144,12 @@ pub(crate) fn build_flow_toolbar( |
| 144 | 144 | actions.exit_to_depth = Some(0); |
| 145 | 145 | } |
| 146 | 146 | for (depth, &group) in scope_path.iter().enumerate() { |
| 147 | let Some(group_node) = comp.nodes.get(group.0) else { | |
| 148 | break; | |
| 149 | }; | |
| 147 | 150 | crumb_sep(ui, depth); |
| 148 | 151 | let current = depth + 1 == scope_path.len(); |
| 149 | let crumb = studio_btn(ui, ("flow-crumb", depth), &comp.node(group).name, current); | |
| 152 | let crumb = studio_btn(ui, ("flow-crumb", depth), &group_node.name, current); | |
| 150 | 153 | if crumb.clicked && !current { |
| 151 | 154 | actions.exit_to_depth = Some(depth + 1); |
| 152 | 155 | } |
crates/flow/src/lib.rs+160-3| ... | ... | @@ -250,7 +250,10 @@ impl FlowView { |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | pub fn resize(&mut self, size: [f32; 2]) { |
| 253 | self.size = [size[0].max(1.0), size[1].max(1.0)]; | |
| 253 | self.size = [ | |
| 254 | if size[0].is_finite() { size[0].max(1.0) } else { 1.0 }, | |
| 255 | if size[1].is_finite() { size[1].max(1.0) } else { 1.0 }, | |
| 256 | ]; | |
| 254 | 257 | } |
| 255 | 258 | |
| 256 | 259 | pub fn background(&self) -> [f32; 4] { |
| ... | ... | @@ -318,8 +321,78 @@ impl FlowView { |
| 318 | 321 | self.fit_comp(comp); |
| 319 | 322 | } |
| 320 | 323 | |
| 324 | /// Sanitizes camera/viewport scalars so `zoom` and `pan` are always finite and positive. | |
| 325 | fn sanitize_view(&mut self) { | |
| 326 | if !self.zoom.is_finite() || self.zoom <= 0.0 { | |
| 327 | self.zoom = 1.0; | |
| 328 | } else { | |
| 329 | self.zoom = self.zoom.clamp(0.12, 3.5); | |
| 330 | } | |
| 331 | if !self.pan[0].is_finite() { | |
| 332 | self.pan[0] = 0.0; | |
| 333 | } | |
| 334 | if !self.pan[1].is_finite() { | |
| 335 | self.pan[1] = 0.0; | |
| 336 | } | |
| 337 | self.resize(self.size); | |
| 338 | } | |
| 339 | ||
| 340 | /// Drops only `NodeId` references and gestures that are no longer valid in `comp`, | |
| 341 | /// keeping active valid gestures intact. | |
| 342 | fn sanitize_stale(&mut self, comp: &Comp) { | |
| 343 | self.sanitize_view(); | |
| 344 | let len = comp.nodes.len(); | |
| 345 | if self.scope.refresh(comp) { | |
| 346 | self.fitted_once = false; | |
| 347 | self.hovered_handle = None; | |
| 348 | self.hovered_wire = None; | |
| 349 | } | |
| 350 | let scope = &self.scope; | |
| 351 | let valid_visible = |id: NodeId| id.0 < len && scope.shows(comp.node(id)); | |
| 352 | self.selected.retain(|id| valid_visible(*id)); | |
| 353 | if self.primary.is_some_and(|id| !valid_visible(id)) { | |
| 354 | self.primary = self.selected.iter().copied().next(); | |
| 355 | } | |
| 356 | for slot in &mut self.viewed_nodes { | |
| 357 | if slot.is_some_and(|id| id.0 >= len) { | |
| 358 | *slot = None; | |
| 359 | } | |
| 360 | } | |
| 361 | if self.hovered_node.is_some_and(|id| !valid_visible(id)) { | |
| 362 | self.hovered_node = None; | |
| 363 | } | |
| 364 | if self.hovered_handle.as_ref().is_some_and(|h| !valid_visible(h.node)) { | |
| 365 | self.hovered_handle = None; | |
| 366 | } | |
| 367 | if self.hovered_wire.as_ref().is_some_and(|w| !valid_visible(w.src) || !valid_visible(w.dst)) { | |
| 368 | self.hovered_wire = None; | |
| 369 | } | |
| 370 | if self.lmb_drag_node.is_some_and(|(id, _, _)| !valid_visible(id)) { | |
| 371 | self.lmb_drag_node = None; | |
| 372 | } | |
| 373 | if self.last_click.is_some_and(|(_, id)| !valid_visible(id)) { | |
| 374 | self.last_click = None; | |
| 375 | } | |
| 376 | if self.modal.as_ref().is_some_and(|m| m.saved_positions.iter().any(|(id, _)| !valid_visible(*id))) { | |
| 377 | self.modal = None; | |
| 378 | self.orphaned_group = true; | |
| 379 | } | |
| 380 | if let Some(wd) = &mut self.wire_drag { | |
| 381 | let stale_src = !valid_visible(wd.src); | |
| 382 | let stale_det = wd.detached_from.as_ref().is_some_and(|(dst, _)| !valid_visible(*dst)); | |
| 383 | if stale_src || stale_det { | |
| 384 | let owns = wd.owns_group(); | |
| 385 | self.wire_drag = None; | |
| 386 | self.orphaned_group |= owns; | |
| 387 | } else if wd.target.as_ref().is_some_and(|t| !valid_visible(t.node)) { | |
| 388 | wd.target = None; | |
| 389 | } | |
| 390 | } | |
| 391 | } | |
| 392 | ||
| 321 | 393 | /// Removes any stale `NodeId`s from selection/viewed_nodes after undo/redo or deletion. |
| 322 | 394 | pub fn sanitize_ids(&mut self, comp: &Comp) { |
| 395 | self.sanitize_view(); | |
| 323 | 396 | let len = comp.nodes.len(); |
| 324 | 397 | if self.scope.refresh(comp) { |
| 325 | 398 | self.fitted_once = false; |
| ... | ... | @@ -333,7 +406,7 @@ impl FlowView { |
| 333 | 406 | *slot = None; |
| 334 | 407 | } |
| 335 | 408 | } |
| 336 | if self.hovered_node.is_some_and(|id| id.0 >= len) { | |
| 409 | if self.hovered_node.is_some_and(|id| id.0 >= len || !self.scope.shows(comp.node(id))) { | |
| 337 | 410 | self.hovered_node = None; |
| 338 | 411 | } |
| 339 | 412 | self.hovered_handle = None; |
| ... | ... | @@ -364,6 +437,7 @@ impl FlowView { |
| 364 | 437 | } |
| 365 | 438 | |
| 366 | 439 | pub fn fit_all(&mut self, comp: &Comp) { |
| 440 | self.sanitize_stale(comp); | |
| 367 | 441 | let ids: Vec<NodeId> = if !self.selected.is_empty() { |
| 368 | 442 | self.selected.iter().copied().collect() |
| 369 | 443 | } else { |
| ... | ... | @@ -373,11 +447,13 @@ impl FlowView { |
| 373 | 447 | } |
| 374 | 448 | |
| 375 | 449 | pub fn fit_comp(&mut self, comp: &Comp) { |
| 450 | self.sanitize_stale(comp); | |
| 376 | 451 | let ids = self.scope.visible(comp); |
| 377 | 452 | self.fit_ids(comp, ids); |
| 378 | 453 | } |
| 379 | 454 | |
| 380 | 455 | fn fit_ids(&mut self, comp: &Comp, target_ids: Vec<NodeId>) { |
| 456 | self.sanitize_view(); | |
| 381 | 457 | if target_ids.is_empty() { |
| 382 | 458 | return; |
| 383 | 459 | } |
| ... | ... | @@ -386,12 +462,19 @@ impl FlowView { |
| 386 | 462 | let mut max_x = f32::NEG_INFINITY; |
| 387 | 463 | let mut max_y = f32::NEG_INFINITY; |
| 388 | 464 | for id in target_ids { |
| 389 | let p = comp.node(id).pos; | |
| 465 | let Some(node) = comp.nodes.get(id.0) else { continue }; | |
| 466 | let p = node.pos; | |
| 467 | if !p[0].is_finite() || !p[1].is_finite() { | |
| 468 | continue; | |
| 469 | } | |
| 390 | 470 | min_x = min_x.min(p[0] - NODE_W * 0.5); |
| 391 | 471 | max_x = max_x.max(p[0] + NODE_W * 0.5); |
| 392 | 472 | min_y = min_y.min(p[1] - NODE_H * 0.5); |
| 393 | 473 | max_y = max_y.max(p[1] + NODE_H * 0.5); |
| 394 | 474 | } |
| 475 | if !min_x.is_finite() || !max_x.is_finite() || !min_y.is_finite() || !max_y.is_finite() { | |
| 476 | return; | |
| 477 | } | |
| 395 | 478 | let span_x = (max_x - min_x).max(200.0); |
| 396 | 479 | let span_y = (max_y - min_y).max(120.0); |
| 397 | 480 | let pad = 64.0; |
| ... | ... | @@ -740,6 +823,7 @@ impl FlowView { |
| 740 | 823 | modifiers: ModifiersState, |
| 741 | 824 | ) -> Vec<FlowAction> { |
| 742 | 825 | let mut actions = Vec::new(); |
| 826 | self.sanitize_stale(comp); | |
| 743 | 827 | self.pointer_local = [pointer_window[0] - rect[0], pointer_window[1] - rect[1]]; |
| 744 | 828 | if std::mem::take(&mut self.orphaned_group) { |
| 745 | 829 | history.commit_group(comp); |
| ... | ... | @@ -991,6 +1075,10 @@ impl FlowView { |
| 991 | 1075 | } |
| 992 | 1076 | |
| 993 | 1077 | fn zoom_at(&mut self, factor: f32, pivot_local: [f32; 2]) { |
| 1078 | self.sanitize_view(); | |
| 1079 | if !factor.is_finite() || !pivot_local[0].is_finite() || !pivot_local[1].is_finite() { | |
| 1080 | return; | |
| 1081 | } | |
| 994 | 1082 | let before = self.local_to_world(pivot_local); |
| 995 | 1083 | self.zoom = (self.zoom * factor).clamp(0.12, 3.5); |
| 996 | 1084 | let after = self.local_to_world(pivot_local); |
| ... | ... | @@ -1645,4 +1733,73 @@ mod tests { |
| 1645 | 1733 | assert!(ports("Key").iter().filter(|(p, _)| p.ends_with(".Matte")).all(|(_, c)| *c == ports::GRAY)); |
| 1646 | 1734 | } |
| 1647 | 1735 | |
| 1736 | #[test] | |
| 1737 | fn stale_ids_mid_modal_wire_drag_and_group_scope_do_not_panic_on_comp_replace() { | |
| 1738 | let (mut comp, mut flow, mut history) = wire_flow(); | |
| 1739 | let merge = id(&comp, "Merge1"); | |
| 1740 | flow.selected.insert(merge); | |
| 1741 | flow.primary = Some(merge); | |
| 1742 | flow.viewed_nodes = [Some(merge), Some(id(&comp, "BG1"))]; | |
| 1743 | ||
| 1744 | // Start modal grab, then replace comp with an empty comp without calling sanitize_ids first. | |
| 1745 | key(&mut flow, &mut comp, &mut history, Key::Character("g".into()), ModifiersState::empty()); | |
| 1746 | assert!(flow.modal.is_some()); | |
| 1747 | let mut empty = Comp::from_fusion_str("Composition {}").expect("empty comp"); | |
| 1748 | flow.fit_all(&empty); | |
| 1749 | flow.prepare_labels(&empty); | |
| 1750 | let _ = flow.paint(&empty); | |
| 1751 | send(&mut flow, &mut empty, &mut history, ui::Event::PointerMoved([20.0, 20.0]), [20.0, 20.0]); | |
| 1752 | key(&mut flow, &mut empty, &mut history, Key::Named(NamedKey::Enter), ModifiersState::empty()); | |
| 1753 | ||
| 1754 | // Start detached wire drag, then replace comp mid-drag before release. | |
| 1755 | let (mut comp2, mut flow2, mut history2) = wire_flow(); | |
| 1756 | let m2 = id(&comp2, "Merge1"); | |
| 1757 | let tri = input_center(&flow2, &comp2, m2, "Background"); | |
| 1758 | send(&mut flow2, &mut comp2, &mut history2, button(true), tri); | |
| 1759 | send(&mut flow2, &mut comp2, &mut history2, ui::Event::PointerMoved([tri[0] + 40.0, tri[1]]), [tri[0] + 40.0, tri[1]]); | |
| 1760 | assert!(flow2.wire_drag.is_some()); | |
| 1761 | send(&mut flow2, &mut empty, &mut history2, button(false), [300.0, 300.0]); | |
| 1762 | let _ = flow2.paint(&empty); | |
| 1763 | ||
| 1764 | // Enter a GroupOperator, then replace comp with one that has no group at that index. | |
| 1765 | let grouped = Comp::from_fusion_str( | |
| 1766 | r#"Composition { Tools = ordered() { | |
| 1767 | G = GroupOperator { Tools = ordered() { Inner = Blur {} } }, | |
| 1768 | } }"#, | |
| 1769 | ) | |
| 1770 | .expect("grouped comp"); | |
| 1771 | let mut flow3 = FlowView::new(&ui::Theme::new(&theme::KNIFE, true)); | |
| 1772 | assert!(flow3.enter_group(&grouped, grouped.find_node("G").unwrap())); | |
| 1773 | assert!(!flow3.scope_path().is_empty()); | |
| 1774 | flow3.prepare_labels(&empty); | |
| 1775 | let _ = flow3.paint(&empty); | |
| 1776 | assert!(flow3.scope_path().is_empty()); | |
| 1777 | } | |
| 1778 | ||
| 1779 | #[test] | |
| 1780 | fn degenerate_zoom_pan_and_zero_viewport_do_not_hang_or_panic() { | |
| 1781 | let mut comp = test_comp(); | |
| 1782 | let bg = id(&comp, "BG1"); | |
| 1783 | comp.set_node_pos(bg, [f32::NAN, 10.0]); | |
| 1784 | let mut history = CompHistory::new(); | |
| 1785 | let mut flow = FlowView::new(&ui::Theme::new(&theme::KNIFE, true)); | |
| 1786 | ||
| 1787 | flow.resize([0.0, 0.0]); | |
| 1788 | flow.zoom = 0.0; | |
| 1789 | flow.pan = [f32::NAN, f32::INFINITY]; | |
| 1790 | let _ = flow.paint(&comp); | |
| 1791 | ||
| 1792 | flow.zoom = 1e-12; | |
| 1793 | flow.pan = [1e12, -1e12]; | |
| 1794 | let _ = flow.paint(&comp); | |
| 1795 | ||
| 1796 | flow.zoom = f32::NAN; | |
| 1797 | flow.fit_all(&comp); | |
| 1798 | flow.prepare_labels(&comp); | |
| 1799 | let _ = flow.paint(&comp); | |
| 1800 | send(&mut flow, &mut comp, &mut history, ui::Event::Wheel([0.0, 12.0]), [10.0, 10.0]); | |
| 1801 | assert!(flow.zoom.is_finite() && flow.zoom > 0.0); | |
| 1802 | assert!(flow.pan.iter().all(|v| v.is_finite())); | |
| 1803 | } | |
| 1804 | ||
| 1648 | 1805 | } |
crates/flow/src/paint.rs+24-15| ... | ... | @@ -18,6 +18,7 @@ fn make_layout(s: &str, font: &text::Font) -> text::Layout { |
| 18 | 18 | |
| 19 | 19 | impl FlowView { |
| 20 | 20 | pub fn prepare_labels(&mut self, comp: &Comp) { |
| 21 | self.sanitize_stale(comp); | |
| 21 | 22 | let mut label_font: Option<text::Font> = None; |
| 22 | 23 | let mut badge_font: Option<text::Font> = None; |
| 23 | 24 | let mut tiny_font: Option<text::Font> = None; |
| ... | ... | @@ -87,27 +88,35 @@ impl FlowView { |
| 87 | 88 | |
| 88 | 89 | pub fn paint<'a>(&'a self, comp: &'a Comp) -> Vec<Primitive<'a>> { |
| 89 | 90 | let mut out = Vec::with_capacity(comp.nodes.len().min(64) * 10 + 128); |
| 90 | let [w, h] = self.size; | |
| 91 | let w = if self.size[0].is_finite() { self.size[0].max(1.0) } else { 1.0 }; | |
| 92 | let h = if self.size[1].is_finite() { self.size[1].max(1.0) } else { 1.0 }; | |
| 93 | let zoom = if self.zoom.is_finite() && self.zoom > 0.0 { self.zoom.clamp(0.12, 3.5) } else { 1.0 }; | |
| 91 | 94 | |
| 92 | 95 | // 1. Subtle architectural grid aligned to Fusion's 110×33 flow cells |
| 93 | let mult = if self.zoom < 0.35 { 4.0 } else if self.zoom < 0.70 { 2.0 } else { 1.0 }; | |
| 96 | let mult = if zoom < 0.35 { 4.0 } else if zoom < 0.70 { 2.0 } else { 1.0 }; | |
| 94 | 97 | let step_x = 110.0 * mult; |
| 95 | 98 | let step_y = 33.0 * mult * 2.0; |
| 96 | 99 | let tl = self.local_to_world([0.0, 0.0]); |
| 97 | 100 | let br = self.local_to_world([w, h]); |
| 98 | let gx0 = (tl[0] / step_x).floor() as i32; | |
| 99 | let gx1 = (br[0] / step_x).ceil() as i32; | |
| 100 | let gy0 = (tl[1] / step_y).floor() as i32; | |
| 101 | let gy1 = (br[1] / step_y).ceil() as i32; | |
| 102 | for gx in gx0..=gx1 { | |
| 103 | let x = self.world_to_local([gx as f32 * step_x, 0.0])[0]; | |
| 104 | let col = if gx % 4 == 0 { self.palette.grid_major } else { self.palette.grid_minor }; | |
| 105 | out.push(Primitive::Segment { from: [x, 0.0], to: [x, h], width: 1.0, color: col }); | |
| 106 | } | |
| 107 | for gy in gy0..=gy1 { | |
| 108 | let y = self.world_to_local([0.0, gy as f32 * step_y])[1]; | |
| 109 | let col = if gy % 4 == 0 { self.palette.grid_major } else { self.palette.grid_minor }; | |
| 110 | out.push(Primitive::Segment { from: [0.0, y], to: [w, y], width: 1.0, color: col }); | |
| 101 | if tl[0].is_finite() && tl[1].is_finite() && br[0].is_finite() && br[1].is_finite() && zoom == self.zoom { | |
| 102 | let gx0 = (tl[0] / step_x).floor() as i32; | |
| 103 | let gx1 = (br[0] / step_x).ceil() as i32; | |
| 104 | let gy0 = (tl[1] / step_y).floor() as i32; | |
| 105 | let gy1 = (br[1] / step_y).ceil() as i32; | |
| 106 | if gx1.saturating_sub(gx0) <= 512 { | |
| 107 | for gx in gx0..=gx1 { | |
| 108 | let x = self.world_to_local([gx as f32 * step_x, 0.0])[0]; | |
| 109 | let col = if gx % 4 == 0 { self.palette.grid_major } else { self.palette.grid_minor }; | |
| 110 | out.push(Primitive::Segment { from: [x, 0.0], to: [x, h], width: 1.0, color: col }); | |
| 111 | } | |
| 112 | } | |
| 113 | if gy1.saturating_sub(gy0) <= 512 { | |
| 114 | for gy in gy0..=gy1 { | |
| 115 | let y = self.world_to_local([0.0, gy as f32 * step_y])[1]; | |
| 116 | let col = if gy % 4 == 0 { self.palette.grid_major } else { self.palette.grid_minor }; | |
| 117 | out.push(Primitive::Segment { from: [0.0, y], to: [w, y], width: 1.0, color: col }); | |
| 118 | } | |
| 119 | } | |
| 111 | 120 | } |
| 112 | 121 | |
| 113 | 122 | // 2. Modal Blender axis-lock guide lines |
crates/flow/src/scope.rs+4-1| ... | ... | @@ -72,7 +72,10 @@ impl Scope { |
| 72 | 72 | if self.is_root() { |
| 73 | 73 | comp.find_node(name).filter(|&id| !comp.node(id).internal) |
| 74 | 74 | } else { |
| 75 | self.members.iter().copied().find(|&id| comp.node(id).name == name) | |
| 75 | self.members | |
| 76 | .iter() | |
| 77 | .copied() | |
| 78 | .find(|&id| comp.nodes.get(id.0).is_some_and(|n| n.name == name)) | |
| 76 | 79 | } |
| 77 | 80 | } |
| 78 | 81 |
crates/spline/src/input.rs+1| ... | ... | @@ -489,6 +489,7 @@ impl SplineView { |
| 489 | 489 | ) -> Vec<SplineAction> { |
| 490 | 490 | let mut actions = Vec::new(); |
| 491 | 491 | self.pointer_local = [pointer_window[0] - rect[0], pointer_window[1] - rect[1]]; |
| 492 | self.sanitize_stale(comp); | |
| 492 | 493 | let plot = self.plot_rect(); |
| 493 | 494 | |
| 494 | 495 | match event { |
crates/spline/src/lib.rs+141-10| ... | ... | @@ -132,7 +132,47 @@ impl SplineView { |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | pub fn resize(&mut self, size: [f32; 2]) { |
| 135 | self.size = [size[0].max(1.0), size[1].max(1.0)]; | |
| 135 | self.size = [ | |
| 136 | if size[0].is_finite() { size[0].max(1.0) } else { 1.0 }, | |
| 137 | if size[1].is_finite() { size[1].max(1.0) } else { 1.0 }, | |
| 138 | ]; | |
| 139 | } | |
| 140 | ||
| 141 | pub(crate) fn sanitize_view(&mut self) { | |
| 142 | self.resize(self.size); | |
| 143 | self.t_range = sanitize_range(self.t_range, [0.0, 300.0], 1e-3); | |
| 144 | self.v_range = sanitize_range(self.v_range, [-0.2, 1.2], 1e-6); | |
| 145 | if !self.pointer_local[0].is_finite() { | |
| 146 | self.pointer_local[0] = 0.0; | |
| 147 | } | |
| 148 | if !self.pointer_local[1].is_finite() { | |
| 149 | self.pointer_local[1] = 0.0; | |
| 150 | } | |
| 151 | } | |
| 152 | ||
| 153 | /// Drops stale node/spline/keyframe references and sanitizes viewport bounds before input or paint. | |
| 154 | pub(crate) fn sanitize_stale(&mut self, comp: &Comp) { | |
| 155 | self.sanitize_view(); | |
| 156 | if self.current_node.is_some_and(|id| id.0 >= comp.nodes.len()) { | |
| 157 | self.refresh_for_comp(comp, None, false); | |
| 158 | return; | |
| 159 | } | |
| 160 | if self.modal.as_ref().is_some_and(|m| { | |
| 161 | m.saved_splines.iter().any(|(sname, orig)| { | |
| 162 | comp.splines.get(sname).is_none_or(|sp| sp.keyframes.len() != orig.len()) | |
| 163 | }) | |
| 164 | }) { | |
| 165 | self.modal = None; | |
| 166 | self.lmb_drag_point = None; | |
| 167 | } | |
| 168 | self.selected.retain(|p| { | |
| 169 | comp.splines.get(&p.spline).is_some_and(|sp| p.key_idx < sp.keyframes.len()) | |
| 170 | }); | |
| 171 | if self.hovered.as_ref().is_some_and(|h| { | |
| 172 | comp.splines.get(&h.spline).is_none_or(|sp| h.key_idx >= sp.keyframes.len()) | |
| 173 | }) { | |
| 174 | self.hovered = None; | |
| 175 | } | |
| 136 | 176 | } |
| 137 | 177 | |
| 138 | 178 | pub fn background(&self) -> [f32; 4] { |
| ... | ... | @@ -234,18 +274,19 @@ impl SplineView { |
| 234 | 274 | } |
| 235 | 275 | } |
| 236 | 276 | |
| 237 | if !t0.is_finite() { | |
| 238 | self.t_range = [comp.render_range[0] as f64, comp.render_range[1] as f64]; | |
| 239 | self.v_range = if self.normalized { [-0.12, 1.12] } else { [-0.2, 1.2] }; | |
| 240 | return; | |
| 277 | if !t0.is_finite() || !t1.is_finite() { | |
| 278 | let r0 = comp.render_range[0] as f64; | |
| 279 | let r1 = comp.render_range[1].max(comp.render_range[0].saturating_add(10)) as f64; | |
| 280 | self.t_range = [r0, r1]; | |
| 281 | } else { | |
| 282 | let dt = (t1 - t0).max(20.0); | |
| 283 | self.t_range = sanitize_range([t0 - dt * 0.14, t1 + dt * 0.14], [0.0, 300.0], 1e-3); | |
| 241 | 284 | } |
| 242 | let dt = (t1 - t0).max(20.0); | |
| 243 | self.t_range = [t0 - dt * 0.14, t1 + dt * 0.14]; | |
| 244 | if self.normalized { | |
| 245 | self.v_range = [-0.12, 1.12]; | |
| 285 | if self.normalized || !v0.is_finite() || !v1.is_finite() { | |
| 286 | self.v_range = if self.normalized { [-0.12, 1.12] } else { [-0.2, 1.2] }; | |
| 246 | 287 | } else { |
| 247 | 288 | let dv = (v1 - v0).max(0.2); |
| 248 | self.v_range = [v0 - dv * 0.20, v1 + dv * 0.20]; | |
| 289 | self.v_range = sanitize_range([v0 - dv * 0.20, v1 + dv * 0.20], [-0.2, 1.2], 1e-6); | |
| 249 | 290 | } |
| 250 | 291 | } |
| 251 | 292 | |
| ... | ... | @@ -304,6 +345,21 @@ impl SplineView { |
| 304 | 345 | } |
| 305 | 346 | } |
| 306 | 347 | |
| 348 | pub(crate) fn sanitize_range(r: [f64; 2], fallback: [f64; 2], min_span: f64) -> [f64; 2] { | |
| 349 | if !r[0].is_finite() || !r[1].is_finite() || r[0] >= r[1] || !(r[1] - r[0]).is_finite() { | |
| 350 | return fallback; | |
| 351 | } | |
| 352 | if r[1] - r[0] < min_span { | |
| 353 | let mid = 0.5 * (r[0] + r[1]); | |
| 354 | let half = 0.5 * min_span; | |
| 355 | if (mid - half).is_finite() && (mid + half).is_finite() { | |
| 356 | return [mid - half, mid + half]; | |
| 357 | } | |
| 358 | return fallback; | |
| 359 | } | |
| 360 | r | |
| 361 | } | |
| 362 | ||
| 307 | 363 | #[cfg(test)] |
| 308 | 364 | pub(crate) mod tests { |
| 309 | 365 | use super::*; |
| ... | ... | @@ -643,4 +699,79 @@ pub(crate) mod tests { |
| 643 | 699 | assert_eq!(comp.splines["Gain"].keyframes[1].flags.linear, linear); |
| 644 | 700 | assert_eq!(comp.revision, revision); |
| 645 | 701 | } |
| 702 | ||
| 703 | #[test] | |
| 704 | fn modal_drag_survives_comp_replace_and_spline_deletion() { | |
| 705 | let mut comp = test_comp(); | |
| 706 | let mut history = CompHistory::new(); | |
| 707 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 708 | view.resize([800.0, 360.0]); | |
| 709 | view.set_target_node(&comp, None); | |
| 710 | view.selected.insert(key_ref(0, HandlePart::Key)); | |
| 711 | ||
| 712 | let rect = [0.0, 0.0, 800.0, 360.0]; | |
| 713 | view.input_with_history(&mut comp, Some(&mut history), 0.0, key_event("g"), rect, [250.0, 150.0], ModifiersState::empty()); | |
| 714 | assert!(view.modal.is_some()); | |
| 715 | ||
| 716 | // Replace comp mid-drag with an empty comp (and a comp with a shrunk spline), without calling refresh_for_comp. | |
| 717 | let mut empty = Comp::from_fusion_str("Composition {}").expect("empty"); | |
| 718 | view.input_with_history(&mut empty, Some(&mut history), 0.0, ui::Event::PointerMoved([290.0, 170.0]), rect, [290.0, 170.0], ModifiersState::empty()); | |
| 719 | view.input_with_history( | |
| 720 | &mut empty, | |
| 721 | Some(&mut history), | |
| 722 | 0.0, | |
| 723 | ui::Event::Key { key: Key::Named(NamedKey::Enter), modifiers: ModifiersState::empty(), text: None }, | |
| 724 | rect, | |
| 725 | [290.0, 170.0], | |
| 726 | ModifiersState::empty(), | |
| 727 | ); | |
| 728 | assert!(view.modal.is_none()); | |
| 729 | assert!(!history.can_undo(), "stale modal must not push old comp snapshot into history"); | |
| 730 | ||
| 731 | view.prepare_labels(&empty); | |
| 732 | let _ = view.paint(&empty, 0.0); | |
| 733 | } | |
| 734 | ||
| 735 | #[test] | |
| 736 | fn empty_single_duplicate_and_nan_splines_paint_and_edit_safely() { | |
| 737 | let mut comp = Comp::from_fusion_str("Composition {}").expect("empty"); | |
| 738 | comp.render_range = [50, 10]; // inverted render range | |
| 739 | comp.splines.insert("Empty".to_owned(), BezierSpline { name: "Empty".to_owned(), color: [200, 200, 200], keyframes: vec![] }); | |
| 740 | comp.splines.insert("One".to_owned(), BezierSpline { name: "One".to_owned(), color: [200, 200, 200], keyframes: vec![Keyframe::new(5.0, 2.0)] }); | |
| 741 | comp.splines.insert("Dup".to_owned(), BezierSpline { | |
| 742 | name: "Dup".to_owned(), | |
| 743 | color: [200, 200, 200], | |
| 744 | keyframes: vec![Keyframe::new(10.0, 0.0), Keyframe::new(10.0, 1.0)], | |
| 745 | }); | |
| 746 | let mut nan_kf = Keyframe::new(f64::NAN, f64::NAN); | |
| 747 | nan_kf.lh = Some([f64::NAN, f64::INFINITY]); | |
| 748 | nan_kf.rh = Some([10.0, f64::NAN]); | |
| 749 | comp.splines.insert("Bad".to_owned(), BezierSpline { | |
| 750 | name: "Bad".to_owned(), | |
| 751 | color: [200, 200, 200], | |
| 752 | keyframes: vec![nan_kf, Keyframe::new(20.0, 5.0)], | |
| 753 | }); | |
| 754 | ||
| 755 | for name in ["Empty", "One", "Dup", "Bad"] { | |
| 756 | let sp = comp.splines.get_mut(name).unwrap(); | |
| 757 | let _ = compute_curve_bounds(sp); | |
| 758 | apply_handle_mode(sp, 0, HandleMode::Auto); | |
| 759 | let _ = presets::apply_easing_preset(sp, &[0], EasingPreset::EaseInOut); | |
| 760 | } | |
| 761 | ||
| 762 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 763 | view.channels = ["Empty", "One", "Dup", "Bad"].into_iter().map(|s| (s.to_owned(), s.to_owned())).collect(); | |
| 764 | view.resize([0.0, 0.0]); | |
| 765 | view.t_range = [100.0, 10.0]; | |
| 766 | view.v_range = [5.0, -5.0]; | |
| 767 | view.fit_all(&comp); | |
| 768 | assert!(view.t_range[0] < view.t_range[1] && view.t_range.iter().all(|v| v.is_finite())); | |
| 769 | assert!(view.v_range[0] < view.v_range[1] && view.v_range.iter().all(|v| v.is_finite())); | |
| 770 | ||
| 771 | view.t_range = [-1e308, 1e308]; | |
| 772 | view.v_range = [f64::NAN, f64::INFINITY]; | |
| 773 | view.prepare_labels(&comp); | |
| 774 | let _ = view.paint(&comp, f64::NAN); | |
| 775 | view.input(&mut comp, 0.0, ui::Event::PointerMoved([50.0, 50.0]), [0.0, 0.0, 0.0, 0.0], [50.0, 50.0], ModifiersState::empty()); | |
| 776 | } | |
| 646 | 777 | } |
crates/spline/src/paint.rs+76-58| ... | ... | @@ -149,6 +149,7 @@ impl SplineView { |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | pub fn prepare_labels(&mut self, comp: &Comp) { |
| 152 | self.sanitize_stale(comp); | |
| 152 | 153 | let cap = super::TEXT_CACHE_CAP.max(self.channels.len() * 2 + 128); |
| 153 | 154 | if self.text_cache.len() > cap { |
| 154 | 155 | self.text_cache.clear(); |
| ... | ... | @@ -230,31 +231,30 @@ impl SplineView { |
| 230 | 231 | } |
| 231 | 232 | |
| 232 | 233 | let mut key_buf = StackBuf::<64>::new(); |
| 233 | let t_step = nice_step((self.t_range[1] - self.t_range[0]) / 8.0); | |
| 234 | let t_start = (self.t_range[0] / t_step).floor() as i64; | |
| 235 | let t_end = (self.t_range[1] / t_step).ceil() as i64; | |
| 236 | for ti in t_start..=t_end { | |
| 237 | let key = write_t_key(&mut key_buf, (ti as f64 * t_step).round() as i64); | |
| 238 | if !self.text_cache.contains_key(key) { | |
| 239 | let layout = make_layout(&key[2..], get_sm(&mut font_sm)); | |
| 240 | self.text_cache.insert(key.to_owned(), layout); | |
| 234 | if let Some((t_step, t_start, t_end)) = grid_ticks(self.t_range, 8.0) { | |
| 235 | for ti in t_start..=t_end { | |
| 236 | let key = write_t_key(&mut key_buf, (ti as f64 * t_step).round() as i64); | |
| 237 | if !self.text_cache.contains_key(key) { | |
| 238 | let layout = make_layout(&key[2..], get_sm(&mut font_sm)); | |
| 239 | self.text_cache.insert(key.to_owned(), layout); | |
| 240 | } | |
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | let v_step = nice_step((self.v_range[1] - self.v_range[0]) / 6.0); | |
| 244 | let v_start = (self.v_range[0] / v_step).floor() as i64; | |
| 245 | let v_end = (self.v_range[1] / v_step).ceil() as i64; | |
| 246 | for vi in v_start..=v_end { | |
| 247 | let key = write_v_key(&mut key_buf, vi as f64 * v_step); | |
| 248 | if !self.text_cache.contains_key(key) { | |
| 249 | let layout = make_layout(&key[2..], get_sm(&mut font_sm)); | |
| 250 | self.text_cache.insert(key.to_owned(), layout); | |
| 243 | if let Some((v_step, v_start, v_end)) = grid_ticks(self.v_range, 6.0) { | |
| 244 | for vi in v_start..=v_end { | |
| 245 | let key = write_v_key(&mut key_buf, vi as f64 * v_step); | |
| 246 | if !self.text_cache.contains_key(key) { | |
| 247 | let layout = make_layout(&key[2..], get_sm(&mut font_sm)); | |
| 248 | self.text_cache.insert(key.to_owned(), layout); | |
| 249 | } | |
| 251 | 250 | } |
| 252 | 251 | } |
| 253 | 252 | } |
| 254 | 253 | |
| 255 | 254 | pub fn paint<'a>(&'a self, comp: &'a Comp, current_frame: f64) -> Vec<Primitive<'a>> { |
| 256 | 255 | let mut out = Vec::with_capacity(512); |
| 257 | let [w, h] = self.size; | |
| 256 | let w = if self.size[0].is_finite() { self.size[0].max(1.0) } else { 1.0 }; | |
| 257 | let h = if self.size[1].is_finite() { self.size[1].max(1.0) } else { 1.0 }; | |
| 258 | 258 | let plot = self.plot_rect(); |
| 259 | 259 | |
| 260 | 260 | self.paint_chrome_and_sidebar(comp, w, h, &mut out); |
| ... | ... | @@ -362,51 +362,49 @@ impl SplineView { |
| 362 | 362 | |
| 363 | 363 | fn paint_grid_and_rulers<'a>(&'a self, plot: [f32; 4], out: &mut Vec<Primitive<'a>>) { |
| 364 | 364 | let mut key_buf = StackBuf::<64>::new(); |
| 365 | let t_step = nice_step((self.t_range[1] - self.t_range[0]) / 8.0); | |
| 366 | let t_start = (self.t_range[0] / t_step).floor() as i64; | |
| 367 | let t_end = (self.t_range[1] / t_step).ceil() as i64; | |
| 368 | for ti in t_start..=t_end { | |
| 369 | let t = ti as f64 * t_step; | |
| 370 | let x = self.data_to_local(t, 0.0)[0]; | |
| 371 | if x < plot[0] || x > plot[2] { | |
| 372 | continue; | |
| 373 | } | |
| 374 | out.push(Primitive::Segment { from: [x, plot[1]], to: [x, plot[3]], width: 1.0, color: self.palette.grid }); | |
| 375 | let key = write_t_key(&mut key_buf, t.round() as i64); | |
| 376 | if let Some(tl) = self.text_cache.get(key) { | |
| 377 | out.push(Primitive::Text { | |
| 378 | text: tl as &dyn Glyphs, | |
| 379 | origin: [x + 3.0, 6.0], | |
| 380 | clip: Some([plot[0], 0.0, plot[2], RULER_H]), | |
| 381 | ink: self.palette.text_dim, | |
| 382 | }); | |
| 365 | if let Some((t_step, t_start, t_end)) = grid_ticks(self.t_range, 8.0) { | |
| 366 | for ti in t_start..=t_end { | |
| 367 | let t = ti as f64 * t_step; | |
| 368 | let x = self.data_to_local(t, 0.0)[0]; | |
| 369 | if x < plot[0] || x > plot[2] { | |
| 370 | continue; | |
| 371 | } | |
| 372 | out.push(Primitive::Segment { from: [x, plot[1]], to: [x, plot[3]], width: 1.0, color: self.palette.grid }); | |
| 373 | let key = write_t_key(&mut key_buf, t.round() as i64); | |
| 374 | if let Some(tl) = self.text_cache.get(key) { | |
| 375 | out.push(Primitive::Text { | |
| 376 | text: tl as &dyn Glyphs, | |
| 377 | origin: [x + 3.0, 6.0], | |
| 378 | clip: Some([plot[0], 0.0, plot[2], RULER_H]), | |
| 379 | ink: self.palette.text_dim, | |
| 380 | }); | |
| 381 | } | |
| 383 | 382 | } |
| 384 | 383 | } |
| 385 | 384 | |
| 386 | let v_step = nice_step((self.v_range[1] - self.v_range[0]) / 6.0); | |
| 387 | let v_start = (self.v_range[0] / v_step).floor() as i64; | |
| 388 | let v_end = (self.v_range[1] / v_step).ceil() as i64; | |
| 389 | for vi in v_start..=v_end { | |
| 390 | let v = vi as f64 * v_step; | |
| 391 | let y = self.data_to_local(0.0, v)[1]; | |
| 392 | if y < plot[1] || y > plot[3] { | |
| 393 | continue; | |
| 394 | } | |
| 395 | let is_zero = v.abs() < 1e-6; | |
| 396 | out.push(Primitive::Segment { | |
| 397 | from: [plot[0], y], | |
| 398 | to: [plot[2], y], | |
| 399 | width: if is_zero { 1.3 } else { 1.0 }, | |
| 400 | color: if is_zero { self.palette.zero_line } else { self.palette.grid }, | |
| 401 | }); | |
| 402 | let key = write_v_key(&mut key_buf, v); | |
| 403 | if let Some(vl) = self.text_cache.get(key) { | |
| 404 | out.push(Primitive::Text { | |
| 405 | text: vl as &dyn Glyphs, | |
| 406 | origin: [plot[0] + 4.0, y - 12.0], | |
| 407 | clip: Some(plot), | |
| 408 | ink: self.palette.text_dim, | |
| 385 | if let Some((v_step, v_start, v_end)) = grid_ticks(self.v_range, 6.0) { | |
| 386 | for vi in v_start..=v_end { | |
| 387 | let v = vi as f64 * v_step; | |
| 388 | let y = self.data_to_local(0.0, v)[1]; | |
| 389 | if y < plot[1] || y > plot[3] { | |
| 390 | continue; | |
| 391 | } | |
| 392 | let is_zero = v.abs() < 1e-6; | |
| 393 | out.push(Primitive::Segment { | |
| 394 | from: [plot[0], y], | |
| 395 | to: [plot[2], y], | |
| 396 | width: if is_zero { 1.3 } else { 1.0 }, | |
| 397 | color: if is_zero { self.palette.zero_line } else { self.palette.grid }, | |
| 409 | 398 | }); |
| 399 | let key = write_v_key(&mut key_buf, v); | |
| 400 | if let Some(vl) = self.text_cache.get(key) { | |
| 401 | out.push(Primitive::Text { | |
| 402 | text: vl as &dyn Glyphs, | |
| 403 | origin: [plot[0] + 4.0, y - 12.0], | |
| 404 | clip: Some(plot), | |
| 405 | ink: self.palette.text_dim, | |
| 406 | }); | |
| 407 | } | |
| 410 | 408 | } |
| 411 | 409 | } |
| 412 | 410 | } |
| ... | ... | @@ -831,7 +829,27 @@ fn spline_color(comp: &Comp, name: &str, idx: usize) -> [f32; 4] { |
| 831 | 829 | PALETTE[idx % PALETTE.len()] |
| 832 | 830 | } |
| 833 | 831 | |
| 832 | fn grid_ticks(range: [f64; 2], divs: f64) -> Option<(f64, i64, i64)> { | |
| 833 | if !range[0].is_finite() || !range[1].is_finite() || range[0] >= range[1] { | |
| 834 | return None; | |
| 835 | } | |
| 836 | let span = range[1] - range[0]; | |
| 837 | if !span.is_finite() || span <= 0.0 { | |
| 838 | return None; | |
| 839 | } | |
| 840 | let step = nice_step(span / divs); | |
| 841 | if !step.is_finite() || step <= 0.0 { | |
| 842 | return None; | |
| 843 | } | |
| 844 | let start = (range[0] / step).floor() as i64; | |
| 845 | let end = (range[1] / step).ceil() as i64; | |
| 846 | (end.saturating_sub(start) <= 256).then_some((step, start, end)) | |
| 847 | } | |
| 848 | ||
| 834 | 849 | fn nice_step(raw: f64) -> f64 { |
| 850 | if !raw.is_finite() { | |
| 851 | return 1.0; | |
| 852 | } | |
| 835 | 853 | let raw = raw.max(1e-6); |
| 836 | 854 | let pow = 10.0_f64.powf(raw.log10().floor()); |
| 837 | 855 | let frac = raw / pow; |
crates/spline/src/presets.rs+1-2| ... | ... | @@ -326,8 +326,7 @@ pub fn compute_curve_bounds(spline: &BezierSpline) -> (f64, f64) { |
| 326 | 326 | return (0.0, 1.0); |
| 327 | 327 | } |
| 328 | 328 | if (max_v - min_v).abs() < 1e-9 { |
| 329 | let v = spline.keyframes[0].value; | |
| 330 | return (v - 0.5, v + 0.5); | |
| 329 | return (min_v - 0.5, min_v + 0.5); | |
| 331 | 330 | } |
| 332 | 331 | (min_v, max_v) |
| 333 | 332 | } |
crates/viewer/src/clock.rs+59-9| ... | ... | @@ -116,7 +116,9 @@ impl PlaybackClock { |
| 116 | 116 | |
| 117 | 117 | /// Exact audio track timestamp (in seconds) for `frame` under `comp.fps` and `comp.audio_offset`. |
| 118 | 118 | pub fn audio_time_for_frame(comp: &Comp, frame: f64) -> f64 { |
| 119 | (frame - comp.audio_offset) / comp.fps.max(1.0) | |
| 119 | let f = if frame.is_finite() { frame } else { 0.0 }; | |
| 120 | let offset = if comp.audio_offset.is_finite() { comp.audio_offset } else { 0.0 }; | |
| 121 | (f - offset) / safe_fps(comp.fps) | |
| 120 | 122 | } |
| 121 | 123 | |
| 122 | 124 | /// Exact audio track timestamp (in seconds) for the current playhead frame. |
| ... | ... | @@ -130,7 +132,7 @@ impl PlaybackClock { |
| 130 | 132 | /// In `EveryFrame`, bounds sub-frame progress to `[0, 1/fps]` so slow frame renders do not |
| 131 | 133 | /// let the audio stream drift ahead of the displayed frame. |
| 132 | 134 | pub fn expected_audio_secs(&self, comp: &Comp, now: Instant) -> f64 { |
| 133 | let fps = comp.fps.max(1.0); | |
| 135 | let fps = safe_fps(comp.fps); | |
| 134 | 136 | if !self.playing { |
| 135 | 137 | return Self::audio_time_for_frame(comp, self.current_frame); |
| 136 | 138 | } |
| ... | ... | @@ -143,7 +145,7 @@ impl PlaybackClock { |
| 143 | 145 | if span <= 1.0 { |
| 144 | 146 | return Self::audio_time_for_frame(comp, r0); |
| 145 | 147 | } |
| 146 | let base = if self.anchor_frame < r0 || self.anchor_frame > r1 { | |
| 148 | let base = if !self.anchor_frame.is_finite() || self.anchor_frame < r0 || self.anchor_frame > r1 { | |
| 147 | 149 | r0 |
| 148 | 150 | } else { |
| 149 | 151 | self.anchor_frame |
| ... | ... | @@ -164,9 +166,11 @@ impl PlaybackClock { |
| 164 | 166 | } |
| 165 | 167 | |
| 166 | 168 | pub fn set_frame(&mut self, comp: &Comp, frame: f64, now: Instant) -> bool { |
| 167 | let clamped = frame | |
| 168 | .round() | |
| 169 | .clamp(comp.global_range[0] as f64, comp.global_range[1] as f64); | |
| 169 | if !frame.is_finite() { | |
| 170 | return false; | |
| 171 | } | |
| 172 | let [g0, g1] = safe_range(comp.global_range); | |
| 173 | let clamped = frame.round().clamp(g0 as f64, g1 as f64); | |
| 170 | 174 | let changed = (clamped - self.current_frame).abs() > 1e-6; |
| 171 | 175 | self.current_frame = clamped; |
| 172 | 176 | if self.playing { |
| ... | ... | @@ -221,8 +225,14 @@ impl PlaybackClock { |
| 221 | 225 | let r0 = p0 as f64; |
| 222 | 226 | let r1 = p1.max(p0) as f64; |
| 223 | 227 | let span = (r1 - r0 + 1.0).max(1.0); |
| 224 | let fps = comp.fps.max(1.0); | |
| 228 | let fps = safe_fps(comp.fps); | |
| 225 | 229 | let frame_dur = Duration::from_secs_f64(1.0 / fps); |
| 230 | if !self.current_frame.is_finite() { | |
| 231 | self.current_frame = r0; | |
| 232 | } | |
| 233 | if !self.anchor_frame.is_finite() { | |
| 234 | self.anchor_frame = r0; | |
| 235 | } | |
| 226 | 236 | |
| 227 | 237 | let mut changed = false; |
| 228 | 238 | let mut looped = false; |
| ... | ... | @@ -252,7 +262,9 @@ impl PlaybackClock { |
| 252 | 262 | let next = r0 + raw.rem_euclid(span); |
| 253 | 263 | if wrapped { |
| 254 | 264 | // Keep the sub-frame overshoot so looping never drifts behind the wall clock. |
| 255 | let overshoot = Duration::from_secs_f64((elapsed * fps - adv) / fps); | |
| 265 | let raw_sub = (elapsed * fps - adv) / fps; | |
| 266 | let sub = if raw_sub.is_finite() { raw_sub.clamp(0.0, 1.0) } else { 0.0 }; | |
| 267 | let overshoot = Duration::from_secs_f64(sub); | |
| 256 | 268 | self.anchor_frame = next; |
| 257 | 269 | self.anchor_time = now.checked_sub(overshoot).unwrap_or(now); |
| 258 | 270 | looped = true; |
| ... | ... | @@ -296,11 +308,19 @@ impl PlaybackClock { |
| 296 | 308 | } |
| 297 | 309 | |
| 298 | 310 | pub fn next_wake(&self, comp: &Comp) -> Duration { |
| 299 | let fps = comp.fps.max(1.0); | |
| 311 | let fps = safe_fps(comp.fps); | |
| 300 | 312 | Duration::from_secs_f64((0.5 / fps).min(0.016)) |
| 301 | 313 | } |
| 302 | 314 | } |
| 303 | 315 | |
| 316 | fn safe_fps(fps: f64) -> f64 { | |
| 317 | if fps.is_finite() { fps.clamp(1.0, 10_000.0) } else { 1.0 } | |
| 318 | } | |
| 319 | ||
| 320 | fn safe_range(range: [i64; 2]) -> [i64; 2] { | |
| 321 | [range[0], range[1].max(range[0])] | |
| 322 | } | |
| 323 | ||
| 304 | 324 | #[cfg(test)] |
| 305 | 325 | mod tests { |
| 306 | 326 | use super::*; |
| ... | ... | @@ -437,4 +457,34 @@ mod tests { |
| 437 | 457 | assert!(!next.looped); |
| 438 | 458 | assert_eq!(clock.current_frame, 21.0); |
| 439 | 459 | } |
| 460 | ||
| 461 | #[test] | |
| 462 | fn playback_clock_handles_degenerate_fps_dt_ranges_and_nan() { | |
| 463 | let mut comp = test_comp(); | |
| 464 | comp.global_range = [50, 10]; // inverted | |
| 465 | comp.render_range = [40, 20]; // inverted | |
| 466 | let t0 = Instant::now(); | |
| 467 | let mut clock = PlaybackClock::new(); | |
| 468 | clock.init_from_comp(&comp); | |
| 469 | ||
| 470 | // NaN frame must not poison current_frame, and inverted global_range must not panic. | |
| 471 | assert!(!clock.set_frame(&comp, f64::NAN, t0)); | |
| 472 | assert!(clock.current_frame.is_finite()); | |
| 473 | ||
| 474 | clock.current_frame = f64::NAN; | |
| 475 | clock.toggle_play(t0); | |
| 476 | for fps in [0.0, -24.0, f64::NAN, f64::INFINITY] { | |
| 477 | comp.fps = fps; | |
| 478 | let res = clock.tick_synced(&comp, t0 + Duration::from_secs(1_000_000_000)); | |
| 479 | assert!(res.playing); | |
| 480 | assert!(clock.current_frame.is_finite()); | |
| 481 | assert!(clock.expected_audio_secs(&comp, t0 + Duration::from_secs(10)).is_finite()); | |
| 482 | let _ = clock.next_wake(&comp); | |
| 483 | } | |
| 484 | ||
| 485 | clock.sync_mode = SyncMode::EveryFrame; | |
| 486 | clock.current_frame = f64::NAN; | |
| 487 | let _ = clock.tick_synced(&comp, t0 + Duration::from_secs(1_000_000_000)); | |
| 488 | assert!(clock.current_frame.is_finite()); | |
| 489 | } | |
| 440 | 490 | } |
crates/viewer/src/gizmos.rs+18-6| ... | ... | @@ -97,11 +97,14 @@ impl GizmoState { |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | fn eval_node_params(&self, comp: &Comp, node: &Node, time: f64) -> NodeGizmoParams { |
| 100 | let center = comp.eval_point(node, "Center", time, [0.5, 0.5], &self.expr); | |
| 101 | let size = comp.eval_number(node, "Size", time, 1.0, &self.expr); | |
| 102 | let angle = comp.eval_number(node, "Angle", time, 0.0, &self.expr); | |
| 103 | let width = comp.eval_number(node, "Width", time, 0.5, &self.expr); | |
| 104 | let height = comp.eval_number(node, "Height", time, 0.5, &self.expr); | |
| 100 | let fin = |v: f64, d: f64| if v.is_finite() { v } else { d }; | |
| 101 | let t = if time.is_finite() { time } else { 0.0 }; | |
| 102 | let c = comp.eval_point(node, "Center", t, [0.5, 0.5], &self.expr); | |
| 103 | let center = [fin(c[0], 0.5), fin(c[1], 0.5)]; | |
| 104 | let size = fin(comp.eval_number(node, "Size", t, 1.0, &self.expr), 1.0); | |
| 105 | let angle = fin(comp.eval_number(node, "Angle", t, 0.0, &self.expr), 0.0); | |
| 106 | let width = fin(comp.eval_number(node, "Width", t, 0.5, &self.expr), 0.5); | |
| 107 | let height = fin(comp.eval_number(node, "Height", t, 0.5, &self.expr), 0.5); | |
| 105 | 108 | NodeGizmoParams { center, size, angle, width, height } |
| 106 | 109 | } |
| 107 | 110 | |
| ... | ... | @@ -230,8 +233,11 @@ impl GizmoState { |
| 230 | 233 | pointer_local: [f32; 2], |
| 231 | 234 | fine: bool, |
| 232 | 235 | ) -> Option<GizmoEdit> { |
| 236 | if !pointer_local[0].is_finite() || !pointer_local[1].is_finite() { | |
| 237 | return None; | |
| 238 | } | |
| 233 | 239 | let d = self.drag.as_ref()?; |
| 234 | if d.node_id.0 >= comp.nodes.len() { | |
| 240 | if !Self::supports_node(comp, d.node_id) { | |
| 235 | 241 | return None; |
| 236 | 242 | } |
| 237 | 243 | let kind = comp.node(d.node_id).kind.as_str(); |
| ... | ... | @@ -502,6 +508,12 @@ impl GizmoState { |
| 502 | 508 | for i in 0..pts.len() { |
| 503 | 509 | let a = &pts[i]; |
| 504 | 510 | let b = &pts[(i + 1) % pts.len()]; |
| 511 | if ![a.x, a.y, a.rx, a.ry, a.lx, a.ly, b.x, b.y, b.lx, b.ly] | |
| 512 | .iter() | |
| 513 | .all(|v| v.is_finite()) | |
| 514 | { | |
| 515 | continue; | |
| 516 | } | |
| 505 | 517 | let p0 = place(a.x, a.y); |
| 506 | 518 | let p1 = place(a.x + a.rx, a.y + a.ry); |
| 507 | 519 | let p2 = place(b.x + b.lx, b.y + b.ly); |
crates/viewer/src/lib.rs+111-8| ... | ... | @@ -236,13 +236,48 @@ impl ViewerState { |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | pub fn resize(&mut self, size: [f32; 2]) { |
| 239 | let clamped = [size[0].max(1.0), size[1].max(1.0)]; | |
| 239 | let clamped = [ | |
| 240 | if size[0].is_finite() { size[0].max(1.0) } else { 1.0 }, | |
| 241 | if size[1].is_finite() { size[1].max(1.0) } else { 1.0 }, | |
| 242 | ]; | |
| 240 | 243 | if (self.size[0] - clamped[0]).abs() > 0.5 || (self.size[1] - clamped[1]).abs() > 0.5 { |
| 241 | 244 | self.size = clamped; |
| 242 | 245 | self.dirty = true; |
| 243 | 246 | } |
| 244 | 247 | } |
| 245 | 248 | |
| 249 | fn sanitize(&mut self, comp: &Comp) { | |
| 250 | self.resize(self.size); | |
| 251 | if !self.zoom.is_finite() || self.zoom <= 0.0 { | |
| 252 | self.zoom = 1.0; | |
| 253 | } else { | |
| 254 | self.zoom = self.zoom.clamp(0.05, 32.0); | |
| 255 | } | |
| 256 | if !self.pan[0].is_finite() { | |
| 257 | self.pan[0] = 0.0; | |
| 258 | } | |
| 259 | if !self.pan[1].is_finite() { | |
| 260 | self.pan[1] = 0.0; | |
| 261 | } | |
| 262 | if !self.pointer_local[0].is_finite() { | |
| 263 | self.pointer_local[0] = 0.0; | |
| 264 | } | |
| 265 | if !self.pointer_local[1].is_finite() { | |
| 266 | self.pointer_local[1] = 0.0; | |
| 267 | } | |
| 268 | let len = comp.nodes.len(); | |
| 269 | if self.viewed_node.is_some_and(|id| id.0 >= len) { | |
| 270 | self.viewed_node = None; | |
| 271 | } | |
| 272 | if self.selected_node.is_some_and(|id| id.0 >= len) { | |
| 273 | self.selected_node = None; | |
| 274 | } | |
| 275 | if self.gizmos.drag.as_ref().is_some_and(|d| !GizmoState::supports_node(comp, d.node_id)) { | |
| 276 | self.gizmos.end_drag(); | |
| 277 | self.gizmos.hovered = None; | |
| 278 | } | |
| 279 | } | |
| 280 | ||
| 246 | 281 | pub fn fit(&mut self) { |
| 247 | 282 | if !self.fit_mode || self.pan != [0.0, 0.0] { |
| 248 | 283 | self.fit_mode = true; |
| ... | ... | @@ -296,7 +331,8 @@ impl ViewerState { |
| 296 | 331 | |
| 297 | 332 | /// Computes `(full_img_rect, visible_rect, uv_rect, effective_scale)` in viewer-local coordinates. |
| 298 | 333 | fn image_layout(&self, comp: &Comp) -> ([f32; 4], [f32; 4], [f32; 4], f32) { |
| 299 | let [w, h] = self.size; | |
| 334 | let w = if self.size[0].is_finite() { self.size[0].max(1.0) } else { 1.0 }; | |
| 335 | let h = if self.size[1].is_finite() { self.size[1].max(1.0) } else { 1.0 }; | |
| 300 | 336 | let top_pad = 30.0; |
| 301 | 337 | let view_h = (h - 34.0).max(20.0); |
| 302 | 338 | let avail_h = (view_h - top_pad - 6.0).max(20.0); |
| ... | ... | @@ -304,13 +340,17 @@ impl ViewerState { |
| 304 | 340 | let ih = comp.height.max(1) as f32; |
| 305 | 341 | let scale = if self.fit_mode { |
| 306 | 342 | ((w - 24.0) / iw).min((avail_h - 4.0) / ih).max(0.05) |
| 343 | } else if self.zoom.is_finite() && self.zoom > 0.0 { | |
| 344 | self.zoom.clamp(0.05, 32.0) | |
| 307 | 345 | } else { |
| 308 | self.zoom | |
| 346 | 1.0 | |
| 309 | 347 | }; |
| 310 | 348 | let dw = iw * scale; |
| 311 | 349 | let dh = ih * scale; |
| 312 | let cx = w * 0.5 + if self.fit_mode { 0.0 } else { self.pan[0] }; | |
| 313 | let cy = top_pad + avail_h * 0.5 + if self.fit_mode { 0.0 } else { self.pan[1] }; | |
| 350 | let pan_x = if self.fit_mode || !self.pan[0].is_finite() { 0.0 } else { self.pan[0] }; | |
| 351 | let pan_y = if self.fit_mode || !self.pan[1].is_finite() { 0.0 } else { self.pan[1] }; | |
| 352 | let cx = w * 0.5 + pan_x; | |
| 353 | let cy = top_pad + avail_h * 0.5 + pan_y; | |
| 314 | 354 | let img = [cx - dw * 0.5, cy - dh * 0.5, cx + dw * 0.5, cy + dh * 0.5]; |
| 315 | 355 | let vp = [4.0, top_pad, (w - 4.0).max(8.0), (view_h - 2.0).max(top_pad + 4.0)]; |
| 316 | 356 | let vis = [ |
| ... | ... | @@ -365,10 +405,13 @@ impl ViewerState { |
| 365 | 405 | current_frame: f64, |
| 366 | 406 | dpi_scale: f32, |
| 367 | 407 | ) { |
| 368 | let Some(target) = self.viewed_node.filter(|id| id.0 < comp.nodes.len()) else { | |
| 408 | self.sanitize(comp); | |
| 409 | let Some(target) = self.viewed_node else { | |
| 369 | 410 | return; |
| 370 | 411 | }; |
| 371 | let frame_i = current_frame.round() as i64; | |
| 412 | let dpi_scale = if dpi_scale.is_finite() && dpi_scale > 0.0 { dpi_scale } else { 1.0 }; | |
| 413 | let frame_f = if current_frame.is_finite() { current_frame } else { comp.render_range[0] as f64 }; | |
| 414 | let frame_i = frame_f.round() as i64; | |
| 372 | 415 | let (_, vis, uv_rect, _) = self.image_layout(comp); |
| 373 | 416 | if vis[2] <= vis[0] + 1.0 || vis[3] <= vis[1] + 1.0 { |
| 374 | 417 | return; |
| ... | ... | @@ -492,7 +535,7 @@ impl ViewerState { |
| 492 | 535 | let r = self.scrubber_rect(); |
| 493 | 536 | let frac = ((local_x - r[0]) / (r[2] - r[0]).max(1.0)).clamp(0.0, 1.0); |
| 494 | 537 | let r0 = comp.render_range[0] as f64; |
| 495 | let r1 = comp.render_range[1].max(comp.render_range[0] + 1) as f64; | |
| 538 | let r1 = comp.render_range[1].max(comp.render_range[0].saturating_add(1)) as f64; | |
| 496 | 539 | (r0 + f64::from(frac) * (r1 - r0)).round() |
| 497 | 540 | } |
| 498 | 541 | |
| ... | ... | @@ -602,6 +645,7 @@ impl ViewerState { |
| 602 | 645 | let mut actions = Vec::new(); |
| 603 | 646 | self.in_out_range = clock.in_out_range; |
| 604 | 647 | self.pointer_local = [pointer_window[0] - rect[0], pointer_window[1] - rect[1]]; |
| 648 | self.sanitize(comp); | |
| 605 | 649 | let scrub = self.scrubber_rect(); |
| 606 | 650 | |
| 607 | 651 | match event { |
| ... | ... | @@ -1019,4 +1063,63 @@ mod tests { |
| 1019 | 1063 | assert!(viewer.cached_frames.is_empty()); |
| 1020 | 1064 | assert!(viewer.last_rendered_sig.is_none()); |
| 1021 | 1065 | } |
| 1066 | ||
| 1067 | #[test] | |
| 1068 | fn viewer_and_gizmos_handle_stale_nodes_zero_poly_nan_params_and_zero_viewport() { | |
| 1069 | let mut comp = Comp::from_fusion_str( | |
| 1070 | r#"Composition { | |
| 1071 | Tools = ordered() { | |
| 1072 | XF = Transform { | |
| 1073 | Inputs = { | |
| 1074 | Center = Input { Value = { 0.5, 0.5 }, }, | |
| 1075 | Size = Input { Value = 1.0, }, | |
| 1076 | }, | |
| 1077 | }, | |
| 1078 | Poly = PolylineMask {}, | |
| 1079 | }, | |
| 1080 | }"#, | |
| 1081 | ) | |
| 1082 | .expect("comp"); | |
| 1083 | let xf = comp.find_node("XF").unwrap(); | |
| 1084 | let poly = comp.find_node("Poly").unwrap(); | |
| 1085 | comp.set_input_value(xf, "Center", model::ParamValue::Point([f64::NAN, f64::INFINITY])); | |
| 1086 | comp.set_input_value(xf, "Size", model::ParamValue::Number(f64::NAN)); | |
| 1087 | comp.set_input_value(xf, "Angle", model::ParamValue::Number(f64::NAN)); | |
| 1088 | ||
| 1089 | let theme = ui::Theme::new(&theme::KNIFE, true); | |
| 1090 | let mut viewer = ViewerState::new(0, &theme); | |
| 1091 | let mut clock = PlaybackClock::new(); | |
| 1092 | let mut eng = Engine::new_headless().expect("gpu"); | |
| 1093 | viewer.resize([0.0, 0.0]); | |
| 1094 | viewer.fit_mode = false; | |
| 1095 | viewer.zoom = 0.0; | |
| 1096 | viewer.pan = [f32::NAN, f32::INFINITY]; | |
| 1097 | viewer.viewed_node = Some(NodeId(99)); // stale | |
| 1098 | viewer.selected_node = Some(xf); | |
| 1099 | ||
| 1100 | let rect = [0.0, 0.0, 0.0, 0.0]; | |
| 1101 | viewer.input(&comp, &clock, ui::Event::PointerMoved([10.0, 10.0]), rect, [10.0, 10.0], ModifiersState::empty()); | |
| 1102 | assert_eq!(viewer.viewed_node, None); | |
| 1103 | assert!(viewer.zoom.is_finite() && viewer.zoom > 0.0); | |
| 1104 | assert!(viewer.pan.iter().all(|v| v.is_finite())); | |
| 1105 | ||
| 1106 | // NaN Transform params and 0-point PolylineMask paint cleanly without NaN propagation. | |
| 1107 | let (img_rect, vis, _, _) = viewer.image_layout(&comp); | |
| 1108 | let _ = viewer.gizmos.paint(&comp, xf, 0.0, img_rect, vis); | |
| 1109 | let _ = viewer.gizmos.paint(&comp, poly, 0.0, img_rect, vis); | |
| 1110 | viewer.viewed_node = Some(xf); | |
| 1111 | viewer.ensure_rendered(&mut eng, &comp, f64::NAN, f32::NAN); | |
| 1112 | let _ = viewer.paint(&comp, f64::NAN); | |
| 1113 | ||
| 1114 | // Mid-drag comp replacement drops stale gizmo drag cleanly. | |
| 1115 | viewer.resize([800.0, 500.0]); | |
| 1116 | let (img_rect, _, _, _) = viewer.image_layout(&comp); | |
| 1117 | let c = GizmoState::fu_to_local([0.5, 0.5], img_rect); | |
| 1118 | assert!(viewer.gizmos.begin_drag(&comp, xf, 0.0, img_rect, c)); | |
| 1119 | let empty = Comp::from_fusion_str("Composition {}").expect("empty"); | |
| 1120 | let acts = viewer.input(&empty, &clock, ui::Event::PointerMoved([c[0] + 10.0, c[1]]), [0.0, 0.0, 800.0, 500.0], [c[0] + 10.0, c[1]], ModifiersState::empty()); | |
| 1121 | assert!(acts.is_empty()); | |
| 1122 | assert!(!viewer.gizmos.is_dragging()); | |
| 1123 | let _ = clock.tick(&empty, Instant::now()); | |
| 1124 | } | |
| 1022 | 1125 | } |