From 237488438b33dbf7cac5fafbd927cf7ec83e2d81 Mon Sep 17 00:00:00 2001 From: Sour Date: Wed, 26 Jan 2022 00:08:17 -0500 Subject: [PATCH] Debugger: Fixed crash when using "exit" menu action --- NewUI/Debugger/Utilities/ContextMenuAction.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/NewUI/Debugger/Utilities/ContextMenuAction.cs b/NewUI/Debugger/Utilities/ContextMenuAction.cs index 67ae661f..16c20b5b 100644 --- a/NewUI/Debugger/Utilities/ContextMenuAction.cs +++ b/NewUI/Debugger/Utilities/ContextMenuAction.cs @@ -1,5 +1,6 @@ using Avalonia.Controls; using Avalonia.Input; +using Avalonia.Threading; using Mesen.Config; using Mesen.Localization; using Mesen.Utilities; @@ -96,7 +97,13 @@ namespace Mesen.Debugger.Utilities set { _onClick = () => { if(IsEnabled == null || IsEnabled()) { - value(); + if(ActionType == ActionType.Exit) { + //When using exit, the command is disposed while the command is running, which causes a crash + //Run the code in a posted action to prevent the crash + Dispatcher.UIThread.Post(() => { value(); }); + } else { + value(); + } } }; _clickCommand = ReactiveCommand.Create(_onClick, this.WhenAnyValue(x => x.Enabled));