Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Expression: crash if using $value + $frame #296

Closed
rodlie opened this issue Nov 1, 2024 · 7 comments
Closed

Apply Expression: crash if using $value + $frame #296

rodlie opened this issue Nov 1, 2024 · 7 comments
Labels
bug Something isn't working expressions help wanted Extra attention is needed svg export
Milestone

Comments

@rodlie
Copy link
Member

rodlie commented Nov 1, 2024

If an expression uses the $value binding, Friction will crash if "Apply Expression" is applied. This issue also affects "Preview SVG" and "Export SVG" as they use "Apply Expression" during export. This does not affect video/image renders.

I assume something in the code tries to read value while generating value and we end up with a crash.

@pgilfernandez
Copy link

Could this workaround be easy to code while you find a real fix for it?:

Before exporting, you could read the "Bindings" and if $value exists you could get the name of the variable, delete that line and create a constant in "Calculate" with the variable name you took from "Bindings" and add manually the value it had at the moment of export...

Does it makes sense? is is possible and easy to code?

@rodlie
Copy link
Member Author

rodlie commented Jan 16, 2025

The issue is $frame.

I created a workaround/hack: 4ee8fe5

It does not crash and actually exports stuff 😄 (limited testing)

Open for other suggestions, I don't like the workaround.

@rodlie
Copy link
Member Author

rodlie commented Jan 18, 2025

@pgilfernandez when you get the time could you test the commit on random expressions? see if it works as expected. No rush.

@pgilfernandez
Copy link

It's working:

  • exporting to SVG or "applying the expression" works! and doesn't crash Friction
  • if you have a constant value on the property it does export as SVG or "apply the expression"

but:

  • if you have an animated value (a keyframed value, that is, the value changes along time) it does work in the viewer but if you either export to SVG or apply the expression it doesn't use it, that is, it doesn't crash but the result is just the animated keyframes without the applied expression.

triple.friction.zip this simple project animates the rotation value from 0 to 90 to 0. The expression triples it (multiplies the value by 3).

@pgilfernandez
Copy link

I did more tests on the subject and I found out some interesting results that might change your fix:

  • Friction doesn't crash when you use $value, it crashes when you use an expression with both $frame and $value, that is, if you have an expression with just $frame or $value it doesn't crash
  • the fix you applied works (even if you don't like it) but...
  • in the case you use just use $value and the property is animated with keyframes then when you export to SVG or "apply the expression" the result is just the value animated and not the result of the expression. More important, this is not a new bug but it has been present since b1 (I can't test previous versions as I'm using macOS builds).

@rodlie
Copy link
Member Author

rodlie commented Jan 19, 2025

Thanks for testing, I noticed last night that we do in fact need both value and frame for it to crash. My "fix" is related to frame, so I just assumed that was the issue.

I don't like the "fix", but It's better than crashing 😄 I just don't want to introduce any new issues/regressions.

in the case you use just use $value and the property is animated with keyframes then when you export to SVG or "apply the expression" the result is just the value animated and not the result of the expression. More important, this is not a new bug but it has been present since b1 (I can't test previous versions as I'm using macOS builds).

Probably always been there, will check.

Note that export to SVG just runs "apply expression" in the background, so any issues are related to that function.

@rodlie rodlie changed the title Apply Expression: crash if using $value Apply Expression: crash if using $value + $frame Jan 19, 2025
@pgilfernandez
Copy link

I don't like the "fix", but It's better than crashing 😄 I just don't want to introduce any new issues/regressions.

Indeed!

Note that export to SVG just runs "apply expression" in the background, so any issues are related to that function.

It makes sense.

This week I will have a look at your hack and see if I can propose a better solution, if not it can stay as it is ,it works, hehehe.

@rodlie rodlie closed this as completed Jan 31, 2025
@rodlie rodlie added this to the 1.0.0 milestone Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working expressions help wanted Extra attention is needed svg export
Projects
None yet
Development

No branches or pull requests

2 participants