From 0552b3db82c4215910580b7db8a04e2f767157c4 Mon Sep 17 00:00:00 2001 From: glax Date: Fri, 1 Sep 2023 22:41:06 +0200 Subject: [PATCH] Fix crash on null Logmessage --- Logging/MemoryLogger.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Logging/MemoryLogger.cs b/Logging/MemoryLogger.cs index 9cc5f95..bf42fef 100644 --- a/Logging/MemoryLogger.cs +++ b/Logging/MemoryLogger.cs @@ -45,14 +45,22 @@ public class MemoryLogger : LoggerBase public string[] GetNewLines() { int logMessageCount = _logMessages.Count; - string[] ret = new string[logMessageCount - _lastLogMessageIndex]; + List ret = new(); - for (int retIndex = 0; retIndex < ret.Length; retIndex++) + int retIndex = 0; + for (; retIndex < logMessageCount - _lastLogMessageIndex; retIndex++) { - ret[retIndex] = _logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString(); + try + { + ret.Add(_logMessages.GetValueAtIndex(_lastLogMessageIndex + retIndex).ToString()); + } + catch (NullReferenceException e)//Called when LogMessage has not finished writing + { + break; + } } - _lastLogMessageIndex = logMessageCount; - return ret; + _lastLogMessageIndex = _lastLogMessageIndex + retIndex; + return ret.ToArray(); } } \ No newline at end of file