Skip to content

Fix name collision between VectorScene.moving_mobjects and Scene.moving_mobjects#4726

Open
m-awais-khan wants to merge 1 commit intoManimCommunity:mainfrom
m-awais-khan:fix-vector-scene-collision
Open

Fix name collision between VectorScene.moving_mobjects and Scene.moving_mobjects#4726
m-awais-khan wants to merge 1 commit intoManimCommunity:mainfrom
m-awais-khan:fix-vector-scene-collision

Conversation

@m-awais-khan
Copy link
Copy Markdown

Fixes a critical name collision bug in VectorScene where LinearTransformationScene crashes during apply_matrix if a UI element (like a label) was previously animated.

Root Cause:
VectorScene initializes a list self.moving_mobjects to keep track of vectors and objects that should undergo linear transformation.
However, the base class Scene overwrites self.moving_mobjects every time self.play(...) is called, using it to track the mobjects currently animating.
If a user calls self.play(FadeIn(label)) right before self.apply_matrix(), the matrix transformation accidentally tries to transform the UI elements from the previous animation instead of the grid and transformable mobjects! This results in ValueError: zip() argument 3 is longer than arguments 1-2 when strict=True is enforced in the Transform.

Fix:
Renamed all internal references of self.moving_mobjects inside VectorScene and LinearTransformationScene to self.vector_moving_mobjects to avoid collision with Scene.moving_mobjects.

Copilot AI review requested due to automatic review settings May 8, 2026 12:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a runtime crash in LinearTransformationScene caused by VectorScene reusing the attribute name moving_mobjects, which conflicts with Scene.moving_mobjects (used internally during play(...)), by renaming the vector-scene-specific list to avoid the collision.

Changes:

  • Renamed VectorScene’s internal tracking list from self.moving_mobjects to self.vector_moving_mobjects.
  • Updated internal call sites that add/use these tracked mobjects during transformations.
  • Updated a related docstring reference (but some documentation still references the old name).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 791 to +806
Adds the mobject to the special list
self.moving_mobject, and adds a property
to the mobject called mobject.target, which
keeps track of what the mobject will move to
or become etc.

Parameters
----------
mobject
The mobjects to add to the list

target_mobject
What the moving_mobject goes to, etc.
"""
mobject.target = target_mobject
self.add_special_mobjects(self.moving_mobjects, mobject)
self.add_special_mobjects(self.vector_moving_mobjects, mobject)
Comment on lines 1089 to 1092
"""
This method returns an animation that moves a mobject
in "self.moving_mobjects" to its corresponding .target value.
in "self.vector_moving_mobjects" to its corresponding .target value.
func is a function that determines where the .target goes.
Comment on lines 697 to 708
def setup(self) -> None:
# The has_already_setup attr is to not break all the old Scenes
if hasattr(self, "has_already_setup"):
return
self.has_already_setup = True
self.background_mobjects: list[Mobject] = []
self.foreground_mobjects: list[Mobject] = []
self.transformable_mobjects: list[Mobject] = []
self.moving_vectors: list[Mobject] = []
self.transformable_labels: list[MathTex] = []
self.moving_mobjects: list[Mobject] = []
self.vector_moving_mobjects: list[Mobject] = []

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants