From da6ff36c2a91c48462f6e0af43379c9c7ec0bf23 Mon Sep 17 00:00:00 2001 From: Sour Date: Tue, 12 Nov 2024 18:43:51 +0900 Subject: [PATCH] Debugger: Memory viewer - Fixed issues with search window caused by recent memory leak-related fixes --- UI/Debugger/ViewModels/MemoryToolsViewModel.cs | 2 +- UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs | 6 +++++- UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs | 8 ++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UI/Debugger/ViewModels/MemoryToolsViewModel.cs b/UI/Debugger/ViewModels/MemoryToolsViewModel.cs index 1c533e121..4501a2460 100644 --- a/UI/Debugger/ViewModels/MemoryToolsViewModel.cs +++ b/UI/Debugger/ViewModels/MemoryToolsViewModel.cs @@ -52,7 +52,7 @@ public MemoryToolsViewModel(HexEditor editor) { Config = ConfigManager.Config.Debug.HexEditor.Clone(); - Search = new(this); + Search = AddDisposable(new MemoryViewerFindViewModel(this)); _editor = editor; Options = AddDisposable(new MemoryToolsDisplayOptionsViewModel(this)); diff --git a/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs b/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs index 75b9aba7b..883751c53 100644 --- a/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs +++ b/UI/Debugger/ViewModels/MemoryViewerFindViewModel.cs @@ -1,4 +1,5 @@ using Avalonia.Controls; +using Avalonia.Threading; using Mesen.Config; using Mesen.Debugger.Utilities; using Mesen.ViewModels; @@ -52,7 +53,10 @@ public MemoryViewerFindViewModel(MemoryToolsViewModel memToolsModel) AddDisposable(this.WhenAnyValue(x => x.SearchString).Subscribe(x => { if(SearchString.Contains(Environment.NewLine)) { - SearchString = SearchString.Replace(Environment.NewLine, " "); + //Run asynchronously to allow the textbox to update its content correctly + Dispatcher.UIThread.Post(() => { + SearchString = SearchString.Replace(Environment.NewLine, " "); + }); } })); diff --git a/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs b/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs index c9a3e8087..c95e0118d 100644 --- a/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs +++ b/UI/Debugger/Windows/MemoryViewerFindWindow.axaml.cs @@ -44,6 +44,14 @@ private void InitializeComponent() AvaloniaXamlLoader.Load(this); } + protected override void OnClosed(EventArgs e) + { + //Prevent MesenWindow logic from disposing the model + DataContext = null; + + base.OnClosed(e); + } + private void OnPreviewKeyDown(object? sender, KeyEventArgs e) { if(e.Key == Key.Enter) {