From a9772efbc415bb78d7a6dd63ac4091d705b36651 Mon Sep 17 00:00:00 2001 From: Souryo Date: Sun, 6 Aug 2017 16:39:14 -0400 Subject: [PATCH] Linux: Fixed crash when closing debugger while other debugger tools are opened --- GUI.NET/Debugger/frmDebugger.cs | 59 ++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 26 deletions(-) diff --git a/GUI.NET/Debugger/frmDebugger.cs b/GUI.NET/Debugger/frmDebugger.cs index 9f7548d7..47393f9e 100644 --- a/GUI.NET/Debugger/frmDebugger.cs +++ b/GUI.NET/Debugger/frmDebugger.cs @@ -541,34 +541,41 @@ namespace Mesen.GUI.Debugger this.Close(); } - protected override void OnFormClosed(FormClosedEventArgs e) + protected override void OnFormClosing(FormClosingEventArgs e) { - tmrCdlRatios.Stop(); - foreach(Form frm in this._childForms.ToArray()) { - frm.Close(); + if(_childForms.Count > 0) { + foreach(Form frm in this._childForms.ToArray()) { + frm.Close(); + } + e.Cancel = true; + + this.BeginInvoke((Action)(() => { + this.Close(); + })); + } else { + tmrCdlRatios.Stop(); + + LabelManager.OnLabelUpdated -= LabelManager_OnLabelUpdated; + BreakpointManager.BreakpointsChanged -= BreakpointManager_BreakpointsChanged; + ctrlConsoleStatus.OnStateChanged -= ctrlConsoleStatus_OnStateChanged; + ctrlProfiler.OnFunctionSelected -= ctrlProfiler_OnFunctionSelected; + + if(_notifListener != null) { + _notifListener.Dispose(); + _notifListener = null; + } + + InteropEmu.DebugRelease(); + + ConfigManager.Config.DebugInfo.WindowWidth = this.WindowState == FormWindowState.Maximized ? this.RestoreBounds.Width : this.Width; + ConfigManager.Config.DebugInfo.WindowHeight = this.WindowState == FormWindowState.Maximized ? this.RestoreBounds.Height : this.Height; + ConfigManager.Config.DebugInfo.TopPanelHeight = this.splitContainer.GetSplitterDistance(); + ConfigManager.Config.DebugInfo.LeftPanelWidth = this.ctrlSplitContainerTop.GetSplitterDistance(); + ConfigManager.ApplyChanges(); + + SaveWorkspace(); } - - LabelManager.OnLabelUpdated -= LabelManager_OnLabelUpdated; - BreakpointManager.BreakpointsChanged -= BreakpointManager_BreakpointsChanged; - ctrlConsoleStatus.OnStateChanged -= ctrlConsoleStatus_OnStateChanged; - ctrlProfiler.OnFunctionSelected -= ctrlProfiler_OnFunctionSelected; - - if(_notifListener != null) { - _notifListener.Dispose(); - _notifListener = null; - } - - InteropEmu.DebugRelease(); - - ConfigManager.Config.DebugInfo.WindowWidth = this.WindowState == FormWindowState.Maximized ? this.RestoreBounds.Width : this.Width; - ConfigManager.Config.DebugInfo.WindowHeight = this.WindowState == FormWindowState.Maximized ? this.RestoreBounds.Height : this.Height; - ConfigManager.Config.DebugInfo.TopPanelHeight = this.splitContainer.GetSplitterDistance(); - ConfigManager.Config.DebugInfo.LeftPanelWidth = this.ctrlSplitContainerTop.GetSplitterDistance(); - ConfigManager.ApplyChanges(); - - SaveWorkspace(); - - base.OnFormClosed(e); + base.OnFormClosing(e); } private void mnuNametableViewer_Click(object sender, EventArgs e)