#3231: evaluate prop.get and expression errors with the footage source

prop.get and Session::expression_errors (Reveal Expression Errors, the
viewer's error banner) built their expression context without the
footage source, so an expression that reads footage pixels
(sampleImage) gave a different value or a spurious error there while
it worked in the render and in expr.errors (#1000).

expr_tools::eval_ctx builds the render's context (expression host and
footage source) for a comp at a time; expr.errors, prop.get,
Session::expression_errors and the script value query all use it.

Fixes #3231
This commit is contained in:
vangel76 committed 2026-11-07 15:42:40 +01:00
1 parent bb2d2005ce
commit fc9eca99a0
5 files changed
+71 -11

No files matched your search

+11 -3
View File
@@ -2,7 +2,7 @@
//! Language menu (the ⓕ button next to an expression), written from the public Expression
//! Language Reference.
use effectcraft_project::{Expression, ItemId, Layer, Property};
use effectcraft_project::{Comp, Expression, ItemId, Layer, Property};
use effectcraft_render::EvalCtx;
use effectcraft_time::Tick;
use serde::Serialize;
@@ -42,8 +42,16 @@ impl ExprError {
/// expressions and the syntax errors that disabled others.
pub fn errors(s: &Session, cid: ItemId, t: Tick) -> Vec<ExprError> {
let Some(comp) = s.project.comp(cid) else { return vec![] };
let ctx = EvalCtx { footage: Some(s.footage.as_ref()), expr: s.expr.as_deref(), ..EvalCtx::new(&s.project, cid, comp, t) };
errors_in(&ctx, s.expr_check, || true).unwrap_or_default()
errors_in(&eval_ctx(s, cid, comp, t), s.expr_check, || true).unwrap_or_default()
}
/// The context to evaluate expressions of comp `cid` at comp time `t` as the render does for the
/// comp at top level: with the session's expression host and its footage source, so
/// `sampleImage()` reads footage pixels instead of failing or sampling transparent (#1000,
/// #3231). `expr.errors`, `prop.get`, [`Session::expression_errors`] and the script value query
/// all evaluate through this one context.
pub fn eval_ctx<'a>(s: &'a Session, cid: ItemId, comp: &'a Comp, t: Tick) -> EvalCtx<'a> {
EvalCtx { footage: Some(s.footage.as_ref()), expr: s.expr.as_deref(), ..EvalCtx::new(&s.project, cid, comp, t) }
}
/// Evaluate diagnostics against an immutable snapshot. Background callers can cancel between
+2 -2
View File
@@ -867,8 +867,8 @@ impl Session {
});
for pr in has {
let text = pr.expr.as_ref().map(|e| e.text.clone()).unwrap_or_default();
let mut ctx = effectcraft_render::EvalCtx::new(&self.project, cid, comp, t);
ctx.expr = Some(host.as_ref());
// With the footage source, so `sampleImage()` doesn't fail here only (#3231).
let ctx = super::expr_tools::eval_ctx(self, cid, comp, t);
if let Err(e) = host.eval(&ctx, l, pr, &pr.value_at(l.layer_time(t))) {
errors.push(json!({"layer": l.id.0, "prop": pr.uid, "name": pr.name, "expression": text, "error": e}));
}
+3 -2
View File
@@ -558,8 +558,9 @@ fn get(s: &mut Session, p: &Value) -> Result<Value> {
} else if pr.has_expression()
&& let (Some(h), Some(comp)) = (s.expr.as_deref(), s.project.comp(cid))
{
let mut ctx = crate::render::EvalCtx::new(&s.project, cid, comp, t);
ctx.expr = Some(h);
// The render's context, footage source included, so `sampleImage()` evaluates here as it
// renders and as `expr.errors` reports it (#3231).
let ctx = super::expr_tools::eval_ctx(s, cid, comp, t);
match h.eval(&ctx, l, pr, &raw) {
Ok(v) => out["evaluated"] = v.to_json(),
Err(e) => {