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

Manim 0.18.1: Updaters don't work with objects which have been added using LaggedStart() #3950

Open
uwezi opened this issue Oct 9, 2024 · 3 comments

Comments

@uwezi
Copy link
Contributor

uwezi commented Oct 9, 2024

Description of bug / unexpected behavior

When adding an object to a scene using LaggedStart() no updaters are recognized:

  • not when using .add_updater() before adding to the scene
  • not always_redraw() objects
  • not when using .add_updater() after adding to the scene

Expected behavior

well, updaters should be executed... Especially when added afterwards

How to reproduce the issue

Code for reproducing the problem
class laggingUpdater(Scene):
    def construct(self):
        vt = ValueTracker(0)
        dot1a = Dot().shift(3*UP)
        dot2a = Dot().shift(2*UP)
        dot3a = always_redraw(lambda:
            Dot().shift(1*UP+vt.get_value()*RIGHT)
        )
        dot1b = Dot().shift(1*DOWN)
        dot2b = Dot().shift(2*DOWN)
        dot3b = always_redraw(lambda:
            Dot().shift(3*DOWN+vt.get_value()*RIGHT)
        )
        def updater(mobj):
            mobj.set_x(vt.get_value())
        dot1a.add_updater(updater)
        dot1b.add_updater(updater)
        self.play(
            LaggedStart(
                Create(dot1a),
                Create(dot2a),
                Create(dot3a)
            )
        )
        self.play(
            Create(dot1b),
            Create(dot2b),
            Create(dot3b)
        )
        dot2a.add_updater(updater)
        dot2b.add_updater(updater)
        self.wait()
        self.play(vt.animate.set_value(7),run_time=4)
        self.wait()

Additional media files

Rendered video
laggingUpdater.mp4

System specifications

System Details
  • OS: Windows 10
  • RAM: enough
  • Python version: 3.11.6
  • Manim v0.18.1
    PASTE HERE
</details>



## Additional comments
https://discord.com/channels/581738731934056449/1293588131999907851/1293588131999907851
@uwezi
Copy link
Contributor Author

uwezi commented Oct 9, 2024

The problem is caused by the fact that updating is suspended during the LaggedStart() animation, but it is not resumed automatically afterwards.

class laggingUpdater(Scene):
    def construct(self):
        vt = ValueTracker(0)
        dot1a = Dot().shift(3*UP)
        dot2a = Dot().shift(2*UP)
        dot3a = always_redraw(lambda:
            Dot().shift(1*UP+vt.get_value()*RIGHT)
        )
        dot1b = Dot().shift(1*DOWN)
        dot2b = Dot().shift(2*DOWN)
        dot3b = always_redraw(lambda:
            Dot().shift(3*DOWN+vt.get_value()*RIGHT)
        )
        def updater(mobj):
            mobj.set_x(vt.get_value())
        dot1a.add_updater(updater)
        dot1b.add_updater(updater)
        self.play(
            LaggedStart(
                Create(dot1a),
                Create(dot2a),
                Create(dot3a)
            )
        )
        self.play(
            Create(dot1b),
            Create(dot2b),
            Create(dot3b)
        )
        dot2a.add_updater(updater)
        dot2b.add_updater(updater)
        dot1a.resume_updating()
        dot2a.resume_updating()
        dot3a.resume_updating()
        self.wait()
        self.play(vt.animate.set_value(7),run_time=4)
        self.wait()
laggingUpdater.mp4

Laifsyn added a commit to Laifsyn/manim_unfinished_animation_group that referenced this issue Oct 9, 2024
This could be a fix to the issue found in ManimCommunity#3950
@Laifsyn
Copy link

Laifsyn commented Oct 9, 2024

A possible fix is to write at
composition.py,
class: AnimationGroup(Animation)
method: begin(self)

    def begin(self) -> None:
        if not self.animations:
            raise ValueError(
                f"Trying to play {self} without animations, this is not supported. "
                "Please add at least one subanimation."
            )

        self.anim_group_time = 0.0
        if self.suspend_mobject_updating:
            self.group.suspend_updating()
        for anim in self.animations:
            anim.begin()
+        else:
+            for anim in self.animations:
+                anim.finish()

I'm actually not sure what's the semantics for else: , but according to what I've read, it's meant to be used as a cleanup which made sense for me in the context of this fix

@movimentum
Copy link

Oh, I'd better look for this bug first than digging into why my old scenes stoped rendering... Solution was similar to @uwezi: mob.resume_updating() after LaggedStart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

3 participants