Catch exception while moving cursor in ConsoleIO

- ConsoleIO bug report by ibspa.
- Also: NullReferenceException when closing connection
This commit is contained in:
ORelio 2015-10-20 22:54:58 +02:00
parent a5bf62bc94
commit e8a8ca4e7a
2 changed files with 23 additions and 11 deletions

View file

@ -337,16 +337,22 @@ namespace MinecraftClient
private static void RemoveOneChar() private static void RemoveOneChar()
{ {
if (buffer.Length > 0) if (buffer.Length > 0)
{
try
{ {
if (Console.CursorLeft == 0) if (Console.CursorLeft == 0)
{ {
Console.CursorLeft = Console.BufferWidth - 1; Console.CursorLeft = Console.BufferWidth - 1;
if (Console.CursorTop > 0)
Console.CursorTop--; Console.CursorTop--;
Console.Write(' '); Console.Write(' ');
Console.CursorLeft = Console.BufferWidth - 1; Console.CursorLeft = Console.BufferWidth - 1;
if (Console.CursorTop > 0)
Console.CursorTop--; Console.CursorTop--;
} }
else Console.Write("\b \b"); else Console.Write("\b \b");
}
catch (ArgumentOutOfRangeException) { /* Console was resized!? */ }
buffer = buffer.Substring(0, buffer.Length - 1); buffer = buffer.Substring(0, buffer.Length - 1);
if (buffer2.Length > 0) if (buffer2.Length > 0)
@ -357,14 +363,19 @@ namespace MinecraftClient
} }
} }
private static void GoBack() private static void GoBack()
{
try
{ {
if (Console.CursorLeft == 0) if (Console.CursorLeft == 0)
{ {
Console.CursorLeft = Console.BufferWidth - 1; Console.CursorLeft = Console.BufferWidth - 1;
if (Console.CursorTop > 0)
Console.CursorTop--; Console.CursorTop--;
} }
else Console.Write('\b'); else Console.Write('\b');
} }
catch (ArgumentOutOfRangeException) { /* Console was resized!? */ }
}
private static void GoLeft() private static void GoLeft()
{ {
if (buffer.Length > 0) if (buffer.Length > 0)

View file

@ -85,6 +85,7 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
catch (SocketException) { return false; } catch (SocketException) { return false; }
catch (NullReferenceException) { return false; }
return true; return true;
} }