From 78af234a5220b27063b47e8c1c669482a20db54d Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 23 May 2018 19:19:27 +0200 Subject: [PATCH] Fix crash when bot unloads in GetText() Reported in #441. Thanks, drcheap! --- MinecraftClient/McTcpClient.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index db109fe0..192b645b 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -454,18 +454,19 @@ namespace MinecraftClient if (Settings.DisplayChatLinks) foreach (string link in links) ConsoleIO.WriteLineFormatted("§8MCC: Link: " + link, false); - for (int i = 0; i < bots.Count; i++) + foreach (ChatBot bot in bots.ToArray()) { try { - bots[i].GetText(text); - bots[i].GetText(text, json); + bot.GetText(text); + if (bots.Contains(bot)) + bot.GetText(text, json); } catch (Exception e) { if (!(e is ThreadAbortException)) { - ConsoleIO.WriteLineFormatted("§8GetText: Got error from " + bots[i].ToString() + ": " + e.ToString()); + ConsoleIO.WriteLineFormatted("§8GetText: Got error from " + bot.ToString() + ": " + e.ToString()); } else throw; //ThreadAbortException should not be caught }