Skip to content

Crash when adding converters to 'list' type (splines) #1731

Description

@Svarov-RZM

Issue description
In some specific cases Synfig can no longer process converters on splines parameters. For example, we have two shapes: rectangle and circle. We want a dot to follow 'rectangle' spline and then half-through the animation jump to 'circle' shape. It's easy to achieve using 'Spline Vertex' converter, we convert origin of a dot and then convert spline parameter to a switch and that's it.
And this scheme works in Synfig 1.0.2 but doesn't in all newer versions starting from 1.2.x.

To reproduce

  1. Create any layer with 'Origin' parameter, let's say Circle.
  2. Convert 'Origin' to 'Spline Vertex'.
  3. Convert 'Spline' parameter of 'Spline Vertex' converter to 'Switch' and Synfig crashes.

It seems to be a global issue and probably affect other converters that can work with splines such as 'Time Loop' for instance but I haven't checked that. Additionally, I attached an example file of the animation described above (it crashes on loading).
VertexListBug.zip

Activity

  1. rodolforg commented on Oct 2, 2020

    @rodolforg
    Contributor

    Confirmed :(

  2. Svarov-RZM commented on Oct 22, 2020

    @Svarov-RZM
    ContributorAuthor

    I started learning C++ not so long ago and was trying to solve this issue because it hinders my workflow. I was able to solve it, but not entirely sure I did it correctly.

    Please check out this commit: Svarov-RZM@baae32c
    I don't know why, but for some reason ValueNode_BLineCalcVertex::operator()(Time t)const in valuenode_blinecalcvertex.cpp was trying to access its own class through pointer (-> operator) instead of accessing it directly (. operator). In short, there were some unnecessary pointer magic and in some cases it would crash in assert call.

    I reworked it to use direct access to ValueNode_BLineCalcVertex class and program doesn't crash anymore. I also did some testing and didn't find any regressions.

    @rodolforg @ice0 what's your opinion on this? Is it appropriate fix?

  3. ice0 commented on Oct 23, 2020

    @ice0
    Collaborator

    Hi! Thanks for the investigating the problem.

    I haven't dug deep on ValueNodes, so this is an assumption. But as I see, when you convert the Spline parameter to Switch, it cannot convert it to the ValueNode_BLine class. The reason it wants to cast is just to check if the spline is looped (Bline is a spline in this context). And it fails because the conversion failed. In this situation, we can assume that the shape not looped.

    So here you need to check if the looped parameter is change animation behavior or not. If not, here's how I suggest to change the code:

    	const ValueBase::List bline = (*bline_)(t).get_list();
    	handle<ValueNode_BLine> bline_value_node( handle<ValueNode_BLine>::cast_dynamic(bline_) );
    	//assert(bline_value_node);
    
    	// For classes that cannot be converted to ValueNode_BLine, we assume they are not looped
    	const bool looped = bline_value_node ? bline_value_node->get_loop() : false;
    
  4. Svarov-RZM commented on Oct 23, 2020

    @Svarov-RZM
    ContributorAuthor

    The reason it wants to cast is just to check if the spline is looped

    As I understand, there's no need for that, because loop parameter is available from ValueBase class, which we can access directly (just like we can access get_list from dereferencing *bline_ pointer).

    So here you need to check if the looped parameter is change animation behavior or not

    Yes, it does change the animation as expected. I compared against 1.0.2 and 1.2.2 versions.
    I am going to run some more tests on weekends and if nothing pop up, I'll send a pull request.

  5. rodolforg commented on Oct 23, 2020

    @rodolforg
    Contributor

    I checked the log history of this file:

    There are a couple of changes after v.1.0.2:

    I'll try to git bisect it, if the first one is not the culprit.

    @Svarov-RZM thank you for investigate it! If you're correct in the solution, other two files valuenode_blinecalc* should be correct too.

  6. rodolforg commented on Oct 24, 2020

    @rodolforg
    Contributor

    Argh, how horrible was building Synfig in those old days.
    I give up lol

    Anyway, are you able to switch the spline for the circle origin without crashing?

  7. ice0 commented on Oct 24, 2020

    @ice0
    Collaborator

    The reason it wants to cast is just to check if the spline is looped

    As I understand, there's no need for that, because loop parameter is available from ValueBase class, which we can access directly (just like we can access get_list from dereferencing *bline_ pointer).

    To get ValueBase from ValueNode, you pass time to it. Thus, the possible loop value can change over time (and may be this will be more correct behavior). On the other hand, any solution would be better than a crash )

  8. Svarov-RZM commented on Oct 24, 2020

    @Svarov-RZM
    ContributorAuthor

    If you're correct in the solution, other two files valuenode_blinecalc* should be correct too

    You're right! The same crash happens in 'Spline Tangent' and 'Spline Width'. The 'Spline Width' converter is broken even more, it doesn't allow you to make conversion, throws an error on attempt such as this:
    SplineWidthBug
    Although, it does allow conversion in 1.2.2 version, so regression was introduced recently.

    Anyway, are you able to switch the spline for the circle origin without crashing?

    Yes, of course, I stated above that my commit solves the issue.

    To get ValueBase from ValueNode, you pass time to it. Thus, the possible loop value can change over time (and may be this will be more correct behavior).

    Could be probably done in the future, but currently GUI doesn't allow you to animate internal 'loop' parameter. For example, if you enter 'animation' mode, change time to 1s and then click 'Unloop' on any slpine it won't create a waypoint, but simply change parameter for the whole animation.

    I sent a pull request. I propose to merge it, wait for regression tests to complete (synfig-tests-regressions) and if everything is alright then we can apply this fix for 'Spline Tangent' and 'Spline Width' converters.

  9. linked a pull request that will close this issueFix crash in Spline Vertex converter (#1731) #1802on Oct 24, 2020
  10. added a commit that references this issue on Dec 9, 2020
    9b580c6
  11. rodolforg commented on May 9, 2021

    @rodolforg
    Contributor

    This issue is already fixed in v1.4.1.

  12. added this to the v1.4.2 milestone on May 12, 2021
  13. added a commit that references this issue on May 16, 2021
    f51ddcd
  14. added 3 commits that reference this issue on May 25, 2021
    58fab3a
    9c5d8b6
    bd5ebd3
  15. added a commit that references this issue on Jul 12, 2021
    f33b4fa
  16. morevnaproject commented on Jul 30, 2021

    @morevnaproject
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions