From 2cf46c04877f8eef92c8354d29dda833bc184a3c Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 11 Apr 2015 12:30:36 +0200 Subject: [PATCH] Fix crash when resizing terminal Bug report by doranchak --- MinecraftClient/ConsoleIO.cs | 44 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index ac627c28..131768bd 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -193,26 +193,36 @@ namespace MinecraftClient writing_lock = true; if (reading) { - string buf = buffer; - string buf2 = buffer2; - ClearLineAndBuffer(); - if (Console.CursorLeft == 0) + try { - Console.CursorLeft = Console.BufferWidth - 1; - Console.CursorTop--; - Console.Write(' '); - Console.CursorLeft = Console.BufferWidth - 1; - Console.CursorTop--; + string buf = buffer; + string buf2 = buffer2; + ClearLineAndBuffer(); + if (Console.CursorLeft == 0) + { + Console.CursorLeft = Console.BufferWidth - 1; + Console.CursorTop--; + Console.Write(' '); + Console.CursorLeft = Console.BufferWidth - 1; + Console.CursorTop--; + } + else Console.Write("\b \b"); + Console.Write(text); + buffer = buf; + buffer2 = buf2; + Console.Write(">" + buffer); + if (buffer2.Length > 0) + { + Console.Write(buffer2 + " \b"); + for (int i = 0; i < buffer2.Length; i++) { GoBack(); } + } } - else Console.Write("\b \b"); - Console.Write(text); - buffer = buf; - buffer2 = buf2; - Console.Write(">" + buffer); - if (buffer2.Length > 0) + catch (ArgumentOutOfRangeException) { - Console.Write(buffer2 + " \b"); - for (int i = 0; i < buffer2.Length; i++) { GoBack(); } + //Console resized: Try again + Console.Write('\n'); + writing_lock = false; + Write(text); } } else Console.Write(text);