Fix IndexError in get_nth_subpath() and ensure it always returns a NumPy array (#4630)

* fix #3569 and #4629

* Add changes to opengl_vectorized_mobject.py

---------

Co-authored-by: Francisco Manríquez Novoa <49853152+chopan050@users.noreply.github.com>
This commit is contained in:
Mingqi Geng 2026-03-18 14:15:45 +00:00 committed by GitHub
commit 21cf9998cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -1227,7 +1227,9 @@ class OpenGLVMobject(OpenGLMobject):
def get_nth_subpath(path_list, n): def get_nth_subpath(path_list, n):
if n >= len(path_list): if n >= len(path_list):
# Create a null path at the very end # Create a null path at the very end
return [path_list[-1][-1]] * nppc if len(path_list) == 0:
return np.tile(np.zeros(3), (nppc, 1))
return np.tile(path_list[-1][-1], (nppc, 1))
path = path_list[n] path = path_list[n]
# Check for useless points at the end of the path and remove them # Check for useless points at the end of the path and remove them
# https://github.com/ManimCommunity/manim/issues/1959 # https://github.com/ManimCommunity/manim/issues/1959

View file

@ -1785,7 +1785,9 @@ class VMobject(Mobject):
def get_nth_subpath(path_list, n): def get_nth_subpath(path_list, n):
if n >= len(path_list): if n >= len(path_list):
# Create a null path at the very end # Create a null path at the very end
return [path_list[-1][-1]] * nppcc if len(path_list) == 0:
return np.tile(np.zeros(3), (nppcc, 1))
return np.tile(path_list[-1][-1], (nppcc, 1))
path = path_list[n] path = path_list[n]
# Check for useless points at the end of the path and remove them # Check for useless points at the end of the path and remove them
# https://github.com/ManimCommunity/manim/issues/1959 # https://github.com/ManimCommunity/manim/issues/1959