Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions sampleImage() and subtraction

  • Jeff Hinkle

    June 1, 2022 at 11:00 pm

    I agree it’s baffling. I can’t see any reason for this behavior. I was able to patch around it by killing the math and just altering the array values to be what I needed, but I have no idea why it’s doing what it’s doing. Thanks for looking at it. Glad it wasn’t some super-simple mistake I made.

  • Filip Vandueren

    June 2, 2022 at 8:27 am

    I’m pretty sure the problem is that you are adding alpha values – which are floats -together and then using that total as an index to an array – which expects an integer.

    Javascript doesn’t really differentiate between Integers and Floats, they are both of class Number but javascript might display something like 1.999999999999 as 2, but that would fail as an array index.

    try this:

    x=parseInt(total-1);

    or this:

    x=Math.round(total-1);

    and it will work.

  • Filip Vandueren

    June 2, 2022 at 8:43 am

    …Except it doesn’t…

    Sorry, I was only checking in the Text-layer.

  • Filip Vandueren

    June 2, 2022 at 9:04 am

    OK,

    I think I noticed a glitch in the interface that briefly displayed a -1 in the value field.

    That got me thinking: probably After Effects is doing an error check before it tries to render the image or something. Or it is trying to execute/check the code at some other edge cases that make it fail the code, but wouldn’t fail when we need it at display/rendertime

    Indeed, explicitly setting total=3 works, setting a=b=c=[1,1,1,1]; works too, so at the time it is checking for the errors, it is not correctly sampling the images.

    using x=Math.max(0,total-1); works

    (if you change the first value of the array back to an integer)

    So all this means total is equal to zero while error-checking, but not while rendering the frame.

    Which is indeed strange that it doens’t occur on text-layers.

  • Dan Ebberts

    June 2, 2022 at 7:56 pm

    Nice sleuthing, Filip. I also saw the -1 flash. I suspect that one possible contributing factor might be the calculation time required for sampleImage(). Maybe, under the hood, there’s some asynchronous calculation going on and sampleImage() isn’t reporting back in time. All speculation on my part, but an interesting mystery…

  • Jeff Hinkle

    June 3, 2022 at 1:48 pm

    [blank stare]

    Not gonna lie, you guys lost me about two turns back. Followed most of that but some was way deeper than my piddling expression knowledge goes. Going to file it under “don’t do it like this” and go back to banging rocks together. Really appreciate you both taking a look at it! Hopefully it was a fun little brain-teaser.

    On the plus side, my boss thought the working project was basically magic, so happy ending, at least.

Page 2 of 2

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy