Fix crash when bot unloads in GetText()

Reported in #441. Thanks, drcheap!
This commit is contained in:
ORelio 2018-05-23 19:19:27 +02:00
parent 1cecf2d788
commit 78af234a52

View file

@ -454,18 +454,19 @@ namespace MinecraftClient
if (Settings.DisplayChatLinks) if (Settings.DisplayChatLinks)
foreach (string link in links) foreach (string link in links)
ConsoleIO.WriteLineFormatted("§8MCC: Link: " + link, false); ConsoleIO.WriteLineFormatted("§8MCC: Link: " + link, false);
for (int i = 0; i < bots.Count; i++) foreach (ChatBot bot in bots.ToArray())
{ {
try try
{ {
bots[i].GetText(text); bot.GetText(text);
bots[i].GetText(text, json); if (bots.Contains(bot))
bot.GetText(text, json);
} }
catch (Exception e) catch (Exception e)
{ {
if (!(e is ThreadAbortException)) 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 else throw; //ThreadAbortException should not be caught
} }