From 49582126c4458ab6a1463a2c088b18524b50b72b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Mon, 15 Jan 2024 07:23:47 +0000 Subject: [PATCH] fix close crash (#40) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #39 Reviewed-on: https://codeberg.org/Eroax/StreamGraph/pulls/40 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- graph_node_renderer/deck_holder_renderer.gd | 21 +++++++++++---------- graph_node_renderer/tab_container_custom.gd | 13 ++++++++----- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index 39e14e5..cfe36d8 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -99,7 +99,7 @@ func _ready() -> void: unsaved_changes_dialog_single_deck.set_meta("tab", tab) unsaved_changes_dialog_single_deck.show() return - close_tab(tab) + await close_tab(tab) ) file_dialog.canceled.connect(disconnect_file_dialog_signals) @@ -161,9 +161,9 @@ func close_tab(tab: int) -> void: var groups := DeckHolder.close_deck(tab_container.get_tab_metadata(tab, "id")) # close tabs associated with this deck's groups for group in groups: - for c_tab in range(tab_container.get_tab_count() - 1, 0, -1): + for c_tab in range(tab_container.get_tab_count() - 1, -1, -1): if tab_container.get_tab_metadata(c_tab, "id") == group: - tab_container.close_tab(tab) + tab_container.close_tab(c_tab) await get_tree().process_frame tab_container.close_tab(tab) @@ -419,27 +419,28 @@ func _notification(what: int) -> void: if range(tab_container.get_tab_count()).any(func(x: int): return tab_container.get_content(x).dirty): unsaved_changes_dialog.show() else: - for i in tab_container.get_tab_count(): - close_tab(i) + #for i in tab_container.get_tab_count(): + #close_tab(i) + for i in range(tab_container.get_tab_count() - 1, -1, -1): + await close_tab(i) get_tree().quit() func _on_unsaved_changes_dialog_single_deck_confirmed() -> void: save_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) - close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) + await close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) func _on_unsaved_changes_dialog_single_deck_custom_action(action: StringName) -> void: if action == &"force_close": - close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) + await close_tab(unsaved_changes_dialog_single_deck.get_meta("tab")) unsaved_changes_dialog_single_deck.hide() func _on_unsaved_changes_dialog_confirmed() -> void: - for i in tab_container.get_tab_count(): - close_tab(i) - + for i in range(tab_container.get_tab_count() - 1, -1, -1): + await close_tab(i) get_tree().quit() diff --git a/graph_node_renderer/tab_container_custom.gd b/graph_node_renderer/tab_container_custom.gd index a7cda3d..1a331c4 100644 --- a/graph_node_renderer/tab_container_custom.gd +++ b/graph_node_renderer/tab_container_custom.gd @@ -43,7 +43,7 @@ func _ready() -> void: if _previous_active_tab > -1: content_container.get_child(_previous_active_tab).visible = false - content_container.get_child(tab).visible = true + content_container.get_child(tab).visible = true tab_changed.emit(tab) _previous_active_tab = tab @@ -98,10 +98,10 @@ func is_empty() -> bool: ## Closes a tab at the index [param tab]. func close_tab(tab: int) -> void: content_container.get_child(tab).queue_free() + _tab_metadata.remove_at(tab) + tab_bar.remove_tab(tab) if !tab_bar.select_previous_available(): tab_bar.select_next_available() - tab_bar.remove_tab(tab) - _tab_metadata.remove_at(tab) tab_closed.emit(tab) if tab_bar.tab_count == 0: _previous_active_tab = -1 @@ -135,7 +135,10 @@ func set_tab_metadata(tab: int, key: String, value: Variant) -> void: ## Returns the metadata value set to the tab at index [param tab_idx] using [method set_tab_metadata]. ## If no metadata was previously set, returns [code]null[/code] by default. func get_tab_metadata(tab: int, key: String, default: Variant = null) -> Variant: - if _tab_metadata.size() - 1 < tab: - return default + #if _tab_metadata.size() - 1 < tab: + #return default + #if tab < _tab_metadata.size(): + #return default + assert(tab < _tab_metadata.size()) var m = _tab_metadata[tab] return m.get(key, default)