Skip to content

Commit 1704374

Browse files
MrDiverpre-commit-ci[bot]JasonGrace2282
authored
Fix animations with zero runtime length to give a useful error instead of a broken pipe (#3491)
* Fix animation group not erroring when instantiated with an empty list * Move error messages into Animation.begin() * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update manim/animation/animation.py * Update manim/animation/composition.py * Update manim/animation/animation.py Co-authored-by: Jason Grace <[email protected]> --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jason Grace <[email protected]>
1 parent d390978 commit 1704374

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

manim/animation/animation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ def begin(self) -> None:
191191
method.
192192
193193
"""
194+
if self.run_time <= 0:
195+
raise ValueError(
196+
f"{self} has a runtime of <= 0 seconds, which cannot be rendered correctly! please set a runtime > 0"
197+
)
194198
self.starting_mobject = self.create_starting_mobject()
195199
if self.suspend_mobject_updating:
196200
# All calls to self.mobject's internal updaters

manim/animation/composition.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ def get_all_mobjects(self) -> Sequence[Mobject]:
8181
return list(self.group)
8282

8383
def begin(self) -> None:
84+
if self.run_time <= 0:
85+
tmp = (
86+
"please set a runtime > 0"
87+
if len(self.animations) != 0
88+
else "Please add at least one Animation"
89+
)
90+
raise ValueError(
91+
f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}."
92+
)
8493
if self.suspend_mobject_updating:
8594
self.group.suspend_updating()
8695
for anim in self.animations:

tests/module/animation/test_composition.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,13 @@ def test_animationgroup_is_passing_remover_to_nested_animationgroups():
169169
assert sqr_animation.remover
170170
assert circ_animation.remover
171171
assert polygon_animation.remover
172+
173+
174+
def test_empty_animation_group_fails():
175+
with pytest.raises(ValueError):
176+
AnimationGroup().begin()
177+
178+
179+
def test_empty_animation_fails():
180+
with pytest.raises(ValueError):
181+
FadeIn(None, run_time=0).begin()

0 commit comments

Comments
 (0)