From 30a19d0966ac3fbfb1f4e56337164f62979ef192 Mon Sep 17 00:00:00 2001 From: Anairkoen Schno Date: Tue, 9 Apr 2019 23:23:35 -0500 Subject: [PATCH] Added lock around Write in StdoutInterceptor --- IPA.Loader/Logging/StdoutInterceptor.cs | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/IPA.Loader/Logging/StdoutInterceptor.cs b/IPA.Loader/Logging/StdoutInterceptor.cs index 88693ce3..09d1cf4c 100644 --- a/IPA.Loader/Logging/StdoutInterceptor.cs +++ b/IPA.Loader/Logging/StdoutInterceptor.cs @@ -19,29 +19,32 @@ namespace IPA.Logging } private string lineBuffer = ""; + private object bufferLock = new object(); public override void Write(string value) { - lineBuffer += value; + lock (bufferLock) + { // avoid threading issues + lineBuffer += value; - var parts = lineBuffer.Split(new[] { Environment.NewLine, "\n", "\r" }, StringSplitOptions.None); - for (int i = 0; i < parts.Length; i++) - { - if (i + 1 == parts.Length) // last element - lineBuffer = parts[i]; - else + var parts = lineBuffer.Split(new[] { Environment.NewLine, "\n", "\r" }, StringSplitOptions.None); + for (int i = 0; i < parts.Length; i++) { - var str = parts[i]; - if (string.IsNullOrEmpty(str)) continue; - if (!isStdErr && WinConsole.IsInitialized) - str = ConsoleColorToForegroundSet(currentColor) + str; - - if (isStdErr) - Logger.stdout.Error(str); + if (i + 1 == parts.Length) // last element + lineBuffer = parts[i]; else - Logger.stdout.Info(str); + { + var str = parts[i]; + if (string.IsNullOrEmpty(str)) continue; + if (!isStdErr && WinConsole.IsInitialized) + str = ConsoleColorToForegroundSet(currentColor) + str; + + if (isStdErr) + Logger.stdout.Error(str); + else + Logger.stdout.Info(str); + } } - } }