From 0935da50deb269549ec4e44f18df77cc71c400d1 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 18 Aug 2017 21:59:30 +1000 Subject: [PATCH] Fix crashing yet again --- MCGalaxy/Network/Socket/TcpSocket.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/MCGalaxy/Network/Socket/TcpSocket.cs b/MCGalaxy/Network/Socket/TcpSocket.cs index b15774520..0ec0c86b7 100644 --- a/MCGalaxy/Network/Socket/TcpSocket.cs +++ b/MCGalaxy/Network/Socket/TcpSocket.cs @@ -147,8 +147,11 @@ namespace MCGalaxy.Network { } static void SendCallback(object sender, SocketAsyncEventArgs e) { - TcpSocket s = (TcpSocket)e.UserToken; + Player p = null; try { + TcpSocket s = (TcpSocket)e.UserToken; + p = s.player; + // TODO: Need to check if all data was sent or not? int sent = e.BytesTransferred; lock (s.sendLock) { @@ -159,13 +162,15 @@ namespace MCGalaxy.Network { // If that happens, SendCallback isn't called so we need to send data here instead if (s.DoSendAsync(s.sendQueue.Dequeue())) return; - if (s.player.disconnected) s.sendQueue.Clear(); + if (p.disconnected) s.sendQueue.Clear(); } } } catch (SocketException) { - s.player.Disconnect(); + if (p != null) p.Disconnect(); } catch (ObjectDisposedException) { // Socket was already closed by another thread + } catch (Exception ex) { + Logger.LogError(ex); } }