From 8beb79a33b167cb64b9ea98e22c1e7aedc4ae578 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sun, 3 Nov 2024 03:36:37 +0200 Subject: [PATCH] Fix memory leak where the project remained referenced in BaseDraw even when its tab was closed Another memory leak remains in Recorder.gd, where the first project forever remains referenced in memory, until the user changes the project from the option button. Perhaps we should remove that option button completely and always record the current project, that also sounds like the intended behavior to me. --- src/Tools/BaseDraw.gd | 2 ++ src/Tools/DesignTools/Eraser.gd | 3 ++- src/Tools/DesignTools/Pencil.gd | 3 ++- src/Tools/DesignTools/Shading.gd | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Tools/BaseDraw.gd b/src/Tools/BaseDraw.gd index 5544679a4..1bea35c0a 100644 --- a/src/Tools/BaseDraw.gd +++ b/src/Tools/BaseDraw.gd @@ -273,6 +273,8 @@ func draw_tool(pos: Vector2i) -> void: func draw_end(pos: Vector2i) -> void: super.draw_end(pos) + _stroke_project = null + _stroke_images = [] _brush_size_dynamics = _brush_size if Tools.dynamics_size != Tools.Dynamics.NONE: _brush_size_dynamics = Tools.brush_size_min diff --git a/src/Tools/DesignTools/Eraser.gd b/src/Tools/DesignTools/Eraser.gd index d4d08fd37..f2e99ac45 100644 --- a/src/Tools/DesignTools/Eraser.gd +++ b/src/Tools/DesignTools/Eraser.gd @@ -92,8 +92,8 @@ func draw_move(pos_i: Vector2i) -> void: func draw_end(pos: Vector2i) -> void: pos = snap_position(pos) - super.draw_end(pos) if _picking_color: + super.draw_end(pos) return if _draw_line: @@ -105,6 +105,7 @@ func draw_end(pos: Vector2i) -> void: draw_fill_gap(_line_start, _line_end) _draw_line = false + super.draw_end(pos) commit_undo() SteamManager.set_achievement("ACH_ERASE_PIXEL") cursor_text = "" diff --git a/src/Tools/DesignTools/Pencil.gd b/src/Tools/DesignTools/Pencil.gd index d4b7f0d76..269503553 100644 --- a/src/Tools/DesignTools/Pencil.gd +++ b/src/Tools/DesignTools/Pencil.gd @@ -164,8 +164,8 @@ func draw_move(pos_i: Vector2i) -> void: func draw_end(pos: Vector2i) -> void: pos = snap_position(pos) - super.draw_end(pos) if _picking_color: + super.draw_end(pos) return if _draw_line: @@ -194,6 +194,7 @@ func draw_end(pos: Vector2i) -> void: draw_tool(v) _fill_inside_rect = Rect2i() + super.draw_end(pos) commit_undo() cursor_text = "" update_random_image() diff --git a/src/Tools/DesignTools/Shading.gd b/src/Tools/DesignTools/Shading.gd index 4dda20c0e..e18ce0615 100644 --- a/src/Tools/DesignTools/Shading.gd +++ b/src/Tools/DesignTools/Shading.gd @@ -291,8 +291,8 @@ func draw_move(pos_i: Vector2i) -> void: func draw_end(pos: Vector2i) -> void: pos = snap_position(pos) - super.draw_end(pos) if _picking_color: + super.draw_end(pos) return if _draw_line: @@ -304,6 +304,7 @@ func draw_end(pos: Vector2i) -> void: draw_fill_gap(_line_start, _line_end) _draw_line = false + super.draw_end(pos) commit_undo() cursor_text = "" update_random_image()