Merge pull request #30 from storytold/pr/never-crash-engine
Never crash: engine without expect() (job polling, commands, menus)
This commit is contained in:
@@ -162,7 +162,7 @@ fn run(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let base = masks.children.len();
|
||||
for k in 0..n_masks {
|
||||
// Depth decides the mode: outlines add, holes subtract.
|
||||
let first = frames.iter().find_map(|f| f.get(k)).expect("mask");
|
||||
let Some(first) = frames.iter().find_map(|f| f.get(k)) else { continue };
|
||||
let mode = if first.depth % 2 == 0 { MaskMode::Add } else { MaskMode::Subtract };
|
||||
let mode = if k == 0 { MaskMode::Add } else { mode };
|
||||
let mut g = build::mask(
|
||||
@@ -173,14 +173,16 @@ fn run(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
build::MASK_COLORS[(base + k) % build::MASK_COLORS.len()],
|
||||
);
|
||||
if frames.len() > 1 {
|
||||
let path = g.get_mut("path").expect("path");
|
||||
for (f, lt) in frames.iter().zip(&layer_times) {
|
||||
if let Some(tr) = f.get(k) {
|
||||
effectcraft_keyframe::set_key(&mut path.keys, Keyframe::new(*lt, KV::Path(tr.path.clone())));
|
||||
if let Some(path) = g.get_mut("path") {
|
||||
for (f, lt) in frames.iter().zip(&layer_times) {
|
||||
if let Some(tr) = f.get(k) {
|
||||
effectcraft_keyframe::set_key(&mut path.keys, Keyframe::new(*lt, KV::Path(tr.path.clone())));
|
||||
}
|
||||
}
|
||||
}
|
||||
let op = g.get_mut("opacity").expect("opacity");
|
||||
if frames.iter().any(|f| f.get(k).is_none()) {
|
||||
if let Some(op) = g.get_mut("opacity")
|
||||
&& frames.iter().any(|f| f.get(k).is_none())
|
||||
{
|
||||
for (f, lt) in frames.iter().zip(&layer_times) {
|
||||
let mut key = Keyframe::new(*lt, KV::Scalar(if f.get(k).is_some() { 100.0 } else { 0.0 }));
|
||||
key.in_interp = Interp::Hold;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! Language menu (the ⓕ button next to an expression), written from the public Expression
|
||||
//! Language Reference.
|
||||
|
||||
use effectcraft_project::{ItemId, Layer, Property};
|
||||
use effectcraft_project::{Expression, ItemId, Layer, Property};
|
||||
use effectcraft_render::EvalCtx;
|
||||
use effectcraft_time::Tick;
|
||||
use serde::Serialize;
|
||||
@@ -45,14 +45,13 @@ pub fn errors(s: &Session, cid: ItemId, t: Tick) -> Vec<ExprError> {
|
||||
let ctx = EvalCtx { footage: Some(s.footage.as_ref()), expr: s.expr.as_deref(), ..EvalCtx::new(&s.project, cid, comp, t) };
|
||||
let mut out = vec![];
|
||||
for (i, l) in comp.layers.iter().enumerate() {
|
||||
let mut props: Vec<&Property> = vec![];
|
||||
let mut props: Vec<(&Property, &Expression)> = vec![];
|
||||
l.props.walk("", &mut |_, p| {
|
||||
if p.expr.as_ref().is_some_and(|e| !e.text.trim().is_empty()) {
|
||||
props.push(p);
|
||||
if let Some(e) = p.expr.as_ref().filter(|e| !e.text.trim().is_empty()) {
|
||||
props.push((p, e));
|
||||
}
|
||||
});
|
||||
for p in props {
|
||||
let e = p.expr.as_ref().expect("filtered");
|
||||
for (p, e) in props {
|
||||
let msg = if e.enabled {
|
||||
match &ctx.expr {
|
||||
Some(h) => h.eval(&ctx, l, p, &p.value_at(l.layer_time(t))).err(),
|
||||
|
||||
@@ -1031,8 +1031,8 @@ fn set_text(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
&& let Some(doc) = super::text_edit::layer_doc(s, lid)
|
||||
&& doc.char_len() > 0
|
||||
&& let Some(obj) = p.as_object()
|
||||
&& let Some(e) = s.state.text_edit.as_mut()
|
||||
{
|
||||
let e = s.state.text_edit.as_mut().expect("checked");
|
||||
let mut st = e.pending.clone().unwrap_or_else(|| doc.insertion_style(r.start));
|
||||
let mut any = false;
|
||||
for (k, v) in obj {
|
||||
|
||||
@@ -136,7 +136,7 @@ fn apply(s: &mut Session, cid: ItemId, lid: LayerId, mode: Mode, cuts: &[Tick])
|
||||
let i = cm.layers.iter().position(|l| l.id == lid).ok_or(EngineError::NoComp)?;
|
||||
let mut ids = vec![lid];
|
||||
for t in cuts {
|
||||
let cur = cm.layers.iter().position(|l| l.id == *ids.last().expect("piece")).unwrap_or(i);
|
||||
let cur = ids.last().and_then(|last| cm.layers.iter().position(|l| l.id == *last)).unwrap_or(i);
|
||||
let l = &mut cm.layers[cur];
|
||||
if !(*t > l.in_point && *t < l.out_point) {
|
||||
continue;
|
||||
|
||||
@@ -72,14 +72,11 @@ fn animator_uid(s: &Session, l: &Layer, p: &Value, cmd: &str) -> Result<u64> {
|
||||
/// Add the properties of `kind` to an animator's Properties group (skipping ones it has).
|
||||
fn add_props(ids: &mut Ids, anim: &mut PropGroup, kind: &str, three_d: bool) -> usize {
|
||||
let list = build::text_anim_props(ids, kind, three_d);
|
||||
let props = match anim.sub_mut("properties") {
|
||||
Some(p) => p,
|
||||
None => {
|
||||
let g = ids.group("properties", "Properties");
|
||||
anim.children.push(g.into());
|
||||
anim.sub_mut("properties").expect("just added")
|
||||
}
|
||||
};
|
||||
if anim.sub("properties").is_none() {
|
||||
let g = ids.group("properties", "Properties");
|
||||
anim.children.push(g.into());
|
||||
}
|
||||
let Some(props) = anim.sub_mut("properties") else { return 0 };
|
||||
let mut n = 0;
|
||||
for pr in list {
|
||||
if props.get(&pr.match_id).is_none() {
|
||||
@@ -161,14 +158,11 @@ pub(crate) fn add_selector(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut ids = Ids(&mut next);
|
||||
let l = layer_mut(proj, cid, lid)?;
|
||||
let anim = l.props.find_group_mut(auid).ok_or_else(|| bad(C, "no such animator"))?;
|
||||
let sels = match anim.sub_mut("selectors") {
|
||||
Some(g) => g,
|
||||
None => {
|
||||
let g = ids.group("selectors", "Selectors");
|
||||
anim.children.insert(0, g.into());
|
||||
anim.sub_mut("selectors").expect("just added")
|
||||
}
|
||||
};
|
||||
if anim.sub("selectors").is_none() {
|
||||
let g = ids.group("selectors", "Selectors");
|
||||
anim.children.insert(0, g.into());
|
||||
}
|
||||
let sels = anim.sub_mut("selectors").ok_or_else(|| bad(C, "the animator has no Selectors group"))?;
|
||||
let (m, label) = match kind.as_str() {
|
||||
"range" => ("rangeSelector", "Range Selector"),
|
||||
"wiggly" => ("wigglySelector", "Wiggly Selector"),
|
||||
|
||||
@@ -455,8 +455,9 @@ pub(crate) fn sanitize(s: &mut Session) {
|
||||
match layer_doc(s, e.layer) {
|
||||
Some(d) => {
|
||||
let n = d.char_len();
|
||||
if e.anchor > n || e.caret > n {
|
||||
let ed = s.state.text_edit.as_mut().expect("checked");
|
||||
if (e.anchor > n || e.caret > n)
|
||||
&& let Some(ed) = s.state.text_edit.as_mut()
|
||||
{
|
||||
ed.anchor = ed.anchor.min(n);
|
||||
ed.caret = ed.caret.min(n);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user