diff --git a/Barotrauma/BarotraumaServer/Source/DebugConsole.cs b/Barotrauma/BarotraumaServer/Source/DebugConsole.cs index 9508d78e1..c06a6807b 100644 --- a/Barotrauma/BarotraumaServer/Source/DebugConsole.cs +++ b/Barotrauma/BarotraumaServer/Source/DebugConsole.cs @@ -178,22 +178,33 @@ namespace Barotrauma private static void RewriteInputToCommandLine(string input) { + if (Console.WindowWidth == 0 || Console.WindowHeight == 0) { return; } + int consoleWidth = Math.Max(Console.WindowWidth, 5); int inputLines = Math.Max((int)Math.Ceiling(input.Length / (float)consoleWidth), 1); int cursorLine = Math.Max((int)Math.Ceiling((input.Length + 1) / (float)consoleWidth), 1); - Console.WriteLine(""); Console.CursorTop -= inputLines; - - string ln = input.Length > 0 ? AutoComplete(input, 0) : ""; - ln += new string(' ', consoleWidth - (ln.Length % consoleWidth)); - Console.ForegroundColor = ConsoleColor.DarkGray; - Console.CursorLeft = 0; - Console.Write(ln); - Console.ForegroundColor = ConsoleColor.White; - Console.CursorLeft = 0; - Console.CursorTop -= cursorLine; - Console.Write(input); - Console.CursorLeft = input.Length % consoleWidth; + try + { + Console.WriteLine(""); Console.CursorTop -= inputLines; + + string ln = input.Length > 0 ? AutoComplete(input, 0) : ""; + ln += new string(' ', consoleWidth - (ln.Length % consoleWidth)); + Console.ForegroundColor = ConsoleColor.DarkGray; + Console.CursorLeft = 0; + Console.Write(ln); + Console.ForegroundColor = ConsoleColor.White; + Console.CursorLeft = 0; + Console.CursorTop -= cursorLine; + Console.Write(input); + Console.CursorLeft = input.Length % consoleWidth; + } + catch (Exception e) + { + string errorMsg = "Failed to write input to command line (window width: " + Console.WindowWidth + ", window height: " + Console.WindowHeight + ", inputLines:" + inputLines + ")\n" + + e.Message + "\n" + e.StackTrace; + GameAnalyticsManager.AddErrorEventOnce("DebugConsole.RewriteInputToCommandLine", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); + } } private static void AssignOnClientRequestExecute(string names, Action onClientRequestExecute)