1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

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.
This commit is contained in:
Diogo Trindade 2023-02-05 15:05:51 +00:00
parent 9f20f52b22
commit a7ed4de575
2 changed files with 6 additions and 3 deletions

View File

@ -14,7 +14,7 @@ namespace Artemis.UI.Screens.Debugger.Logs;
public class LogsDebugView : ReactiveUserControl<LogsDebugViewModel> public class LogsDebugView : ReactiveUserControl<LogsDebugViewModel>
{ {
private int _lineCount; private int _lineCount;
private TextEditor _textEditor; private TextEditor? _textEditor;
public LogsDebugView() public LogsDebugView()
{ {
@ -31,7 +31,7 @@ public class LogsDebugView : ReactiveUserControl<LogsDebugViewModel>
protected override void OnInitialized() protected override void OnInitialized()
{ {
base.OnInitialized(); base.OnInitialized();
Dispatcher.UIThread.Post(() => _textEditor.ScrollToEnd(), DispatcherPriority.ApplicationIdle); Dispatcher.UIThread.Post(() => _textEditor?.ScrollToEnd(), DispatcherPriority.ApplicationIdle);
} }
private void OnTextChanged(object? sender, EventArgs e) private void OnTextChanged(object? sender, EventArgs e)

View File

@ -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(); using StringWriter writer = new();
_formatter.Format(logEvent, writer); _formatter.Format(logEvent, writer);
string line = writer.ToString(); string line = writer.ToString();