Fix crash when a bot unloads in OnDisconnect()

See #817
This commit is contained in:
ORelio 2019-12-08 20:18:40 +01:00
parent d1674a2d74
commit 64d62373c9

View file

@ -353,7 +353,7 @@ namespace MinecraftClient
/// </summary>
public void Disconnect()
{
foreach (ChatBot bot in bots)
foreach (ChatBot bot in bots.ToArray())
bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Disconnected");
botsOnHold.Clear();
@ -433,7 +433,7 @@ namespace MinecraftClient
Settings.MCSettings_ChatColors,
Settings.MCSettings_Skin_All,
Settings.MCSettings_MainHand);
foreach (ChatBot bot in bots)
foreach (ChatBot bot in bots.ToArray())
bot.AfterGameJoined();
if (inventoryHandlingRequested)
{
@ -753,7 +753,7 @@ namespace MinecraftClient
break;
}
foreach (ChatBot bot in bots)
foreach (ChatBot bot in bots.ToArray())
will_restart |= bot.OnDisconnect(reason, message);
if (!will_restart)