From 750fae4713f3baf6b3cb824834a49edbf01e505b Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Sat, 11 Dec 2021 21:29:32 +0200 Subject: [PATCH] Project data no longer remain in memory after the user has removed their tab --- src/Classes/Project.gd | 37 +++++++++++++++++++++---------------- src/Main.gd | 2 +- src/UI/Tabs.gd | 5 ++--- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 84e96bb52..80e12700f 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -23,8 +23,8 @@ var fps := 6.0 var x_symmetry_point var y_symmetry_point -var x_symmetry_axis: SymmetryGuide -var y_symmetry_axis: SymmetryGuide +var x_symmetry_axis := SymmetryGuide.new() +var y_symmetry_axis := SymmetryGuide.new() var selection_bitmap := BitMap.new() # This is useful for when the selection is outside of the canvas boundaries, @@ -64,21 +64,17 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> x_symmetry_point = size.x / 2 y_symmetry_point = size.y / 2 - if !x_symmetry_axis: - x_symmetry_axis = SymmetryGuide.new() - x_symmetry_axis.type = x_symmetry_axis.Types.HORIZONTAL - x_symmetry_axis.project = self - x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point)) - x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point)) - Global.canvas.add_child(x_symmetry_axis) + x_symmetry_axis.type = x_symmetry_axis.Types.HORIZONTAL + x_symmetry_axis.project = self + x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point)) + x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point)) + Global.canvas.add_child(x_symmetry_axis) - if !y_symmetry_axis: - y_symmetry_axis = SymmetryGuide.new() - y_symmetry_axis.type = y_symmetry_axis.Types.VERTICAL - y_symmetry_axis.project = self - y_symmetry_axis.add_point(Vector2(x_symmetry_point, -19999)) - y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999)) - Global.canvas.add_child(y_symmetry_axis) + y_symmetry_axis.type = y_symmetry_axis.Types.VERTICAL + y_symmetry_axis.project = self + y_symmetry_axis.add_point(Vector2(x_symmetry_point, -19999)) + y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999)) + Global.canvas.add_child(y_symmetry_axis) if OS.get_name() == "HTML5": directory_path = "user://" @@ -88,6 +84,15 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) -> ) +func remove() -> void: + for layer in layers: + layer.frame_container.queue_free() + undo_redo.free() + for guide in guides: + guide.queue_free() + Global.projects.erase(self) + + func commit_undo() -> void: if Global.canvas.selection.is_moving_content: Global.canvas.selection.transform_content_cancel() diff --git a/src/Main.gd b/src/Main.gd index b465f31d3..1e3ac4fed 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -513,6 +513,6 @@ func _exit_tree() -> void: var i := 0 for project in Global.projects: - project.undo_redo.free() + project.remove() OpenSave.remove_backup(i) i += 1 diff --git a/src/UI/Tabs.gd b/src/UI/Tabs.gd index 70b61cb37..013b79a02 100644 --- a/src/UI/Tabs.gd +++ b/src/UI/Tabs.gd @@ -23,7 +23,7 @@ func _on_Tabs_tab_close(tab: int) -> void: func _on_Tabs_reposition_active_tab_request(idx_to: int) -> void: - var temp = Global.projects[Global.current_project_index] + var temp: Project = Global.projects[Global.current_project_index] Global.projects.erase(temp) Global.projects.insert(idx_to, temp) @@ -38,11 +38,10 @@ func _on_Tabs_reposition_active_tab_request(idx_to: int) -> void: func delete_tab(tab: int) -> void: remove_tab(tab) - Global.projects[tab].undo_redo.free() + Global.projects[tab].remove() OpenSave.remove_backup(tab) OpenSave.current_save_paths.remove(tab) OpenSave.backup_save_paths.remove(tab) - Global.projects.remove(tab) if Global.current_project_index == tab: if tab > 0: Global.current_project_index -= 1