From a7ed4de57555799a5de4a4b594ca51d874d4b738 Mon Sep 17 00:00:00 2001 From: Diogo Trindade Date: Sun, 5 Feb 2023 15:05:51 +0000 Subject: [PATCH] Debugger - Fixed possible crash when LogEvent is null In theory this shouldn't happen, but I just got a hard crash because of it. Doesn't hurt to check. --- .../Screens/Debugger/Tabs/Logs/LogsDebugView.axaml.cs | 4 ++-- .../Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugView.axaml.cs b/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugView.axaml.cs index 20bb00ff2..132d4606a 100644 --- a/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugView.axaml.cs +++ b/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugView.axaml.cs @@ -14,7 +14,7 @@ namespace Artemis.UI.Screens.Debugger.Logs; public class LogsDebugView : ReactiveUserControl { private int _lineCount; - private TextEditor _textEditor; + private TextEditor? _textEditor; public LogsDebugView() { @@ -31,7 +31,7 @@ public class LogsDebugView : ReactiveUserControl protected override void OnInitialized() { base.OnInitialized(); - Dispatcher.UIThread.Post(() => _textEditor.ScrollToEnd(), DispatcherPriority.ApplicationIdle); + Dispatcher.UIThread.Post(() => _textEditor?.ScrollToEnd(), DispatcherPriority.ApplicationIdle); } private void OnTextChanged(object? sender, EventArgs e) diff --git a/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs b/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs index ca067a392..37d85d39d 100644 --- a/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs +++ b/src/Artemis.UI/Screens/Debugger/Tabs/Logs/LogsDebugViewModel.cs @@ -48,8 +48,11 @@ public class LogsDebugViewModel : ActivatableViewModelBase }); } - private void AddLogEvent(LogEvent logEvent) + private void AddLogEvent(LogEvent? logEvent) { + if (logEvent is null) + return; + using StringWriter writer = new(); _formatter.Format(logEvent, writer); string line = writer.ToString();