Skip to content
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

Fix memory leak and slowing down when video output is enabled #158

Merged
merged 1 commit into from
Dec 16, 2023
Merged
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
7 changes: 6 additions & 1 deletion modules/gui/emulator_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(self, window: Tk):
self.frame: Union[ttk.Frame, None] = None
self.canvas: Union[Canvas, None] = None
self.current_canvas_image: Union[PhotoImage, None] = None
self._current_canvas_image_id: int | None = None
self._placeholder_image: Union[PhotoImage, None] = None
self.center_of_canvas: tuple[int, int] = (240, 160)

Expand Down Expand Up @@ -140,10 +141,14 @@ def _generate_placeholder_image(self):
self.canvas.create_image(self.center_of_canvas, image=self.current_canvas_image, state="normal")

def _update_image(self, image: PIL.Image):
if self._current_canvas_image_id:
self.canvas.delete(self._current_canvas_image_id)
self.current_canvas_image = PIL.ImageTk.PhotoImage(
image=image.resize((self.width * self.scale, self.height * self.scale), resample=False)
)
self.canvas.create_image(self.center_of_canvas, image=self.current_canvas_image, state="normal")
self._current_canvas_image_id = self.canvas.create_image(
self.center_of_canvas, image=self.current_canvas_image, state="normal"
)
self._update_window()

def _update_window(self):
Expand Down