From 3ffdd4df2e61973d3f9b38adbb6f7a481db2d15d Mon Sep 17 00:00:00 2001 From: Taksh Date: Tue, 30 Jun 2026 16:20:45 +0530 Subject: [PATCH] fix(vmobject): clear error for non-finite points in point_from_proportion Functions returning NaN/inf (e.g. a negative base to a fractional power) made every curve length NaN, so the loop fell through to a misleading 'file a bug report' exception. Raise a clear ValueError for non-finite points, and fall back to the last point on float-rounding fallthrough. Fixes #4838. --- manim/mobject/types/vectorized_mobject.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/manim/mobject/types/vectorized_mobject.py b/manim/mobject/types/vectorized_mobject.py index 768091ea65..fc6dc7e5ff 100644 --- a/manim/mobject/types/vectorized_mobject.py +++ b/manim/mobject/types/vectorized_mobject.py @@ -1592,6 +1592,16 @@ def construct(self): if alpha == 1: return self.points[-1] + # Non-finite points (e.g. a function returning NaN/inf) make every + # length NaN, so the comparisons below always fail and the loop falls + # through. Surface a clear error instead of an unreachable one. + if not np.all(np.isfinite(self.points)): + raise ValueError( + "Cannot compute point_from_proportion for a VMobject with " + "non-finite points; check that the underlying function does " + "not return NaN or infinite values." + ) + curves_and_lengths = tuple(self.get_curve_functions_with_lengths()) target_length = alpha * sum(length for _, length in curves_and_lengths) @@ -1607,9 +1617,9 @@ def construct(self): return curve(residue) current_length += length - raise Exception( - "Not sure how you reached here, please file a bug report at https://github.com/ManimCommunity/manim/issues/new/choose" - ) + # Floating-point summation can leave current_length just short of + # target_length on the final curve; fall back to the last point. + return self.points[-1] def proportion_from_point( self,