From 178eff308e45b13058ced769926dcf519ecbdf50 Mon Sep 17 00:00:00 2001 From: John Lewin Date: Tue, 20 Nov 2018 16:39:20 -0800 Subject: [PATCH] Revise refs and listeners so MainViewWidget finalizes after Close --- .../Library/Widgets/LibraryWidget.cs | 2 + .../PartPreviewWindow/MainViewWidget.cs | 77 ++++++++++--------- Submodules/agg-sharp | 2 +- 3 files changed, 45 insertions(+), 36 deletions(-) diff --git a/MatterControlLib/Library/Widgets/LibraryWidget.cs b/MatterControlLib/Library/Widgets/LibraryWidget.cs index 9ca6d633d..e708062fd 100644 --- a/MatterControlLib/Library/Widgets/LibraryWidget.cs +++ b/MatterControlLib/Library/Widgets/LibraryWidget.cs @@ -1056,6 +1056,8 @@ namespace MatterHackers.MatterControl.PrintLibrary ApplicationController.Instance.Library.ContainerChanged -= Library_ContainerChanged; } + mainViewWidget = null; + base.OnClosed(e); } diff --git a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs index 9d2b57530..0e70a014b 100644 --- a/MatterControlLib/PartPreviewWindow/MainViewWidget.cs +++ b/MatterControlLib/PartPreviewWindow/MainViewWidget.cs @@ -35,7 +35,6 @@ using MatterHackers.Agg; using MatterHackers.Agg.Platform; using MatterHackers.Agg.UI; using MatterHackers.Localizations; -using MatterHackers.MatterControl.CustomWidgets; using MatterHackers.MatterControl.PartPreviewWindow.PlusTab; using MatterHackers.MatterControl.PrintLibrary; using MatterHackers.MatterControl.SlicerConfiguration; @@ -84,33 +83,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow Border = new BorderDouble(left: 1), }; - tabControl.PlusClicked += (s, e) => + tabControl.PlusClicked += (s, e) => UiThread.RunOnIdle(() => { - UiThread.RunOnIdle(() => - { - this.CreatePartTab().ConfigureAwait(false); - }); - }; - - tabControl.ActiveTabChanged += (s, e) => - { - if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage) - { - var dragDropData = ApplicationController.Instance.DragDropData; - - // Set reference on tab change - dragDropData.View3DWidget = tabPage.view3DWidget; - dragDropData.SceneContext = tabPage.sceneContext; - - ApplicationController.Instance.PrinterTabSelected = true; - } - else - { - ApplicationController.Instance.PrinterTabSelected = false; - } - - ApplicationController.Instance.MainTabKey = tabControl.SelectedTabKey; - }; + this.CreatePartTab().ConfigureAwait(false); + }); // Force the ActionArea to be as high as ButtonHeight tabControl.TabBar.ActionArea.MinimumSize = new Vector2(0, theme.ButtonHeight); @@ -269,13 +245,6 @@ namespace MatterHackers.MatterControl.PartPreviewWindow }; statusBar.AddChild(tasksContainer); - var tasks = ApplicationController.Instance.Tasks; - - tasks.TasksChanged += (s, e) => - { - RenderRunningTasks(theme, tasks); - }; - stretchStatusPanel = new GuiWidget() { HAnchor = HAnchor.Stretch, @@ -297,11 +266,13 @@ namespace MatterHackers.MatterControl.PartPreviewWindow statusBar.AddChild( this.CreateNetworkStatusPanel(theme)); - this.RenderRunningTasks(theme, tasks); + this.RenderRunningTasks(theme, ApplicationController.Instance.Tasks); // Register listeners PrinterSettings.AnyPrinterSettingChanged += Printer_SettingChanged; ApplicationController.Instance.OpenPrintersChanged += OpenPrinters_Changed; + ApplicationController.Instance.Tasks.TasksChanged += Tasks_TasksChanged; + tabControl.ActiveTabChanged += TabControl_ActiveTabChanged; UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent((s, e) => { @@ -311,6 +282,31 @@ namespace MatterHackers.MatterControl.PartPreviewWindow ApplicationController.Instance.MainView = this; } + private void TabControl_ActiveTabChanged(object sender, EventArgs e) + { + if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage) + { + var dragDropData = ApplicationController.Instance.DragDropData; + + // Set reference on tab change + dragDropData.View3DWidget = tabPage.view3DWidget; + dragDropData.SceneContext = tabPage.sceneContext; + + ApplicationController.Instance.PrinterTabSelected = true; + } + else + { + ApplicationController.Instance.PrinterTabSelected = false; + } + + ApplicationController.Instance.MainTabKey = tabControl.SelectedTabKey; + } + + private void Tasks_TasksChanged(object sender, EventArgs e) + { + this.RenderRunningTasks(theme, ApplicationController.Instance.Tasks); + } + private void ShowUpdateAvailableAnimation() { double displayTime = 2; @@ -624,11 +620,22 @@ namespace MatterHackers.MatterControl.PartPreviewWindow // Unregister listeners PrinterSettings.AnyPrinterSettingChanged -= Printer_SettingChanged; UserSettings.Instance.SettingChanged -= SetLinkButtonsVisibility; + ApplicationController.Instance.OpenPrintersChanged -= OpenPrinters_Changed; + ApplicationController.Instance.Tasks.TasksChanged -= Tasks_TasksChanged; + tabControl.ActiveTabChanged -= TabControl_ActiveTabChanged; unregisterEvents?.Invoke(this, null); base.OnClosed(e); } +#if DEBUG + ~MainViewWidget() + { + Console.WriteLine(); + } +#endif + + private void Printer_SettingChanged(object s, EventArgs e) { if (s is PrinterSettings printerSettings diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 5a7724c7e..d1b74de45 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 5a7724c7e220386edba8ce13d4746a23b645f051 +Subproject commit d1b74de45747f7652e501afd62a6c266f0fce83c