Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed MovingCamera bug where frame was not updated properly

Grant Sanderson3f6376af3959
diff --git a/camera/camera.py b/camera/camera.py
index fcaea8e7e..6a3c832bc 100644
--- a/camera/camera.py
+++ b/camera/camera.py
@@ -285,9 +285,18 @@ class Camera(object):
# Methods associated with svg rendering
+ def get_cached_cairo_context(self, pixel_array):
+ return self.pixel_array_to_cairo_context.get(
+ id(pixel_array), None
+ )
+
+ def cache_cairo_context(self, pixel_array, ctx):
+ self.pixel_array_to_cairo_context[id(pixel_array)] = ctx
+
def get_cairo_context(self, pixel_array):
- if id(pixel_array) in self.pixel_array_to_cairo_context:
- return self.pixel_array_to_cairo_context[id(pixel_array)]
+ cached_ctx = self.get_cached_cairo_context(pixel_array)
+ if cached_ctx:
+ return cached_ctx
pw = self.get_pixel_width()
ph = self.get_pixel_height()
fw = self.get_frame_width()
@@ -304,7 +313,7 @@ class Camera(object):
0, -fdiv(ph, fh),
pw / 2, ph / 2,
))
- self.pixel_array_to_cairo_context[id(pixel_array)] = ctx
+ self.cache_cairo_context(pixel_array, ctx)
return ctx
def display_multiple_vectorized_mobjects(self, vmobjects, pixel_array):
diff --git a/camera/moving_camera.py b/camera/moving_camera.py
index 21b7f9479..6b986d7a6 100644
--- a/camera/moving_camera.py
+++ b/camera/moving_camera.py
@@ -74,6 +74,15 @@ class MovingCamera(Camera):
# self.realign_frame_shape()
Camera.capture_mobjects(self, mobjects, **kwargs)
+ # Since the frame can be moving around, the cairo
+ # context used for updating should be regenerated
+ # at each frame. So no caching.
+ def get_cached_cairo_context(self, pixel_array):
+ return None
+
+ def cache_cairo_context(self, pixel_array, ctx):
+ pass
+
# def reset_frame_center(self):
# self.frame_center = self.frame.get_center()