Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fix animations with zero runtime length to give a useful error instead of a broken pipe (#3491)

Tristan Schulz17043747efc0
diff --git a/manim/animation/animation.py b/manim/animation/animation.py
index ddacb37c6..75629ecb5 100644
--- a/manim/animation/animation.py
+++ b/manim/animation/animation.py
@@ -191,6 +191,10 @@ class Animation:
method.
"""
+ if self.run_time <= 0:
+ raise ValueError(
+ f"{self} has a runtime of <= 0 seconds, which cannot be rendered correctly! please set a runtime > 0"
+ )
self.starting_mobject = self.create_starting_mobject()
if self.suspend_mobject_updating:
# All calls to self.mobject's internal updaters
diff --git a/manim/animation/composition.py b/manim/animation/composition.py
index cc6fa2ca7..20b23d828 100644
--- a/manim/animation/composition.py
+++ b/manim/animation/composition.py
@@ -81,6 +81,15 @@ class AnimationGroup(Animation):
return list(self.group)
def begin(self) -> None:
+ if self.run_time <= 0:
+ tmp = (
+ "please set a runtime > 0"
+ if len(self.animations) != 0
+ else "Please add at least one Animation"
+ )
+ raise ValueError(
+ f"{self} has a runtime of 0 seconds. Which cannot be rendered correctly! {tmp}."
+ )
if self.suspend_mobject_updating:
self.group.suspend_updating()
for anim in self.animations:
diff --git a/tests/module/animation/test_composition.py b/tests/module/animation/test_composition.py
index 73cc6b0d6..1f6d6bf5c 100644
--- a/tests/module/animation/test_composition.py
+++ b/tests/module/animation/test_composition.py
@@ -169,3 +169,13 @@ def test_animationgroup_is_passing_remover_to_nested_animationgroups():
assert sqr_animation.remover
assert circ_animation.remover
assert polygon_animation.remover
+
+
+def test_empty_animation_group_fails():
+ with pytest.raises(ValueError):
+ AnimationGroup().begin()
+
+
+def test_empty_animation_fails():
+ with pytest.raises(ValueError):
+ FadeIn(None, run_time=0).begin()