(30e7a1617) Added an error check & exception handling to DebugConsole.RewriteInputToCommandLine (cherry-picked from respawn-overhaul, accidentally commited in the wrong branch)

This commit is contained in:
Joonas Rikkonen
2019-06-09 17:38:40 +03:00
parent a70319bbd2
commit 771f8d7286
@@ -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<Client, Vector2, string[]> onClientRequestExecute)