manim
manim copied to clipboard
Scene.wait (and .pause) calls add an empty Mobject to self.mobjects
Description of bug / unexpected behavior
After each call to Scene's pause() method, I notice a mobject being added to the scene.
class PauseMobjects(Scene):
def construct(self):
print(self.mobjects)
yellow = Square()
self.play(FadeIn(yellow))
print(self.mobjects)
for i in range(0, 5):
self.pause()
print(self.mobjects)
Console while running above:
[]
[Square]
[Square, Mobject]
[Square, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject]
[Square, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject, Mobject]
Nothing is rendered here, but I worry that these excess mobjects could be reducing performance, especially because hasing the scene is O(n) where n is the number of mobjects in the scene (e.g. #2710 )
Expected behavior
I would not expect pausing or otherwise waiting to change the mobjects in the scene. From what I've poked around, it's not apparent to me that adding a Mobject is important for waits, so hopefully this can be removed.
Discussion
I am working on a fix, trying to figure out where this mobject is added and prevent that, or at least make sure the mobject is cleaned up after the animation finishes.
This is with v0.16.0
Of note, this is with the Cairo renderer, which may be important as I'm figuring out where the mobject is coming from.
With the fix in #3041, the console now looks like:
[]
[Square]
[Square]
[Square]
[Square]
[Square]
[Square]
...
as I would expect.
Hello and thanks for the report !
This issue is a long date known issue, there is already one there #1524. I'm closing #1524 in favor of this one, more documented and with a PR attached.
Note : the fix proposed by @AntonBallmaier in its original issue looks like a very clean way to do it. No idea wether it would work
I also tried "simply passing Wait the remover=True keyword", but that did not work. It appears the Wait animation is not cleaned up in the same way as other animations because it is special-cased in several places.