Skip to content

[EXPERIMENTAL] Change order of statements in OpenGLVMobject.__init__() to prevent crashes in subclasses #4056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions manim/mobject/opengl/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from dataclasses import dataclass
from functools import partialmethod, wraps
from math import ceil
from typing import TYPE_CHECKING, Generic
from typing import TYPE_CHECKING, Any, Generic

import numpy as np
from typing_extensions import TypedDict, TypeVar
Expand Down Expand Up @@ -103,14 +103,15 @@ class MobjectStatus:

# TODO: add this to the **kwargs of all mobjects that use OpenGLMobject
class MobjectKwargs(TypedDict, total=False):
color: ParsableManimColor | Sequence[ParsableManimColor] | None
opacity: float
reflectiveness: float
shadow: float
gloss: float
is_fixed_in_frame: bool
is_fixed_orientation: bool
depth_test: bool
name: str
name: str | None


class OpenGLMobject:
Expand All @@ -135,7 +136,7 @@ class OpenGLMobject:
# TypedDict above so that autocomplete works for users
def __init__(
self,
color=WHITE,
color: ParsableManimColor | Sequence[ParsableManimColor] | None = WHITE,
opacity: float = 1.0,
reflectiveness: float = 0.0,
shadow: float = 0.0,
Expand All @@ -144,7 +145,7 @@ def __init__(
is_fixed_orientation: bool = False,
depth_test: bool = True,
name: str | None = None,
**kwargs, # just dump
**kwargs: Any, # just dump
):
self.color = color
self.opacity = opacity
Expand Down
33 changes: 18 additions & 15 deletions manim/mobject/opengl/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,19 @@

# TODO: add this to the **kwargs of all mobjects that use OpenGLVMobject
class VMobjectKwargs(MobjectKwargs, total=False):
color: ParsableManimColor | list[ParsableManimColor]
fill_color: ParsableManimColor | list[ParsableManimColor]
fill_opacity: float
stroke_color: ParsableManimColor | list[ParsableManimColor]
stroke_opacity: float
color: ParsableManimColor | Sequence[ParsableManimColor] | None
fill_color: ParsableManimColor | Sequence[ParsableManimColor] | None
fill_opacity: float | None
stroke_color: ParsableManimColor | Sequence[ParsableManimColor] | None
stroke_opacity: float | None
stroke_width: float
draw_stroke_behind_fill: bool
background_image_file: str
background_image_file: str | None
long_lines: bool
joint_type: LineJointType
flat_stroke: bool
shade_in_3d: bool
checkerboard_colors: bool # TODO: remove


class OpenGLVMobject(OpenGLMobject):
Expand All @@ -95,17 +97,10 @@ def __init__(
long_lines: bool = False,
joint_type: LineJointType = LineJointType.AUTO,
flat_stroke: bool = False,
shade_in_3d=False, # TODO: Can be ignored for now but we should think about using some sort of shader to introduce lighting after deferred rendering has completed
checkerboard_colors=False, # ignore,
shade_in_3d: bool = False, # TODO: Can be ignored for now but we should think about using some sort of shader to introduce lighting after deferred rendering has completed
checkerboard_colors: bool = False, # ignore,
**kwargs: Unpack[MobjectKwargs],
):
super().__init__(**kwargs)
if fill_color is None:
fill_color = self.color
if stroke_color is None:
stroke_color = self.color
self.set_fill(color=fill_color, opacity=fill_opacity)
self.set_stroke(color=stroke_color, opacity=stroke_opacity)
self.stroke_width = listify(stroke_width)
self.draw_stroke_behind_fill = draw_stroke_behind_fill
self.background_image_file = background_image_file
Expand All @@ -116,6 +111,14 @@ def __init__(
self.needs_new_triangulation = True
self.triangulation = np.zeros(0, dtype="i4")

super().__init__(**kwargs)
if fill_color is None:
fill_color = self.color
if stroke_color is None:
stroke_color = self.color
self.set_fill(color=fill_color, opacity=fill_opacity)
self.set_stroke(color=stroke_color, width=stroke_width, opacity=stroke_opacity)

# self.refresh_unit_normal()

def _assert_valid_submobjects(self, submobjects: Iterable[OpenGLVMobject]) -> Self:
Expand Down
Loading