(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,10 +178,14 @@ namespace Barotrauma
private static void RewriteInputToCommandLine(string input) private static void RewriteInputToCommandLine(string input)
{ {
if (Console.WindowWidth == 0 || Console.WindowHeight == 0) { return; }
int consoleWidth = Math.Max(Console.WindowWidth, 5); int consoleWidth = Math.Max(Console.WindowWidth, 5);
int inputLines = Math.Max((int)Math.Ceiling(input.Length / (float)consoleWidth), 1); 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); int cursorLine = Math.Max((int)Math.Ceiling((input.Length + 1) / (float)consoleWidth), 1);
try
{
Console.WriteLine(""); Console.CursorTop -= inputLines; Console.WriteLine(""); Console.CursorTop -= inputLines;
string ln = input.Length > 0 ? AutoComplete(input, 0) : ""; string ln = input.Length > 0 ? AutoComplete(input, 0) : "";
@@ -195,6 +199,13 @@ namespace Barotrauma
Console.Write(input); Console.Write(input);
Console.CursorLeft = input.Length % consoleWidth; 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) private static void AssignOnClientRequestExecute(string names, Action<Client, Vector2, string[]> onClientRequestExecute)
{ {