diff --git a/Library/RSBot.Core/Components/SpawnManager.cs b/Library/RSBot.Core/Components/SpawnManager.cs index e2b89c0a..66657555 100644 --- a/Library/RSBot.Core/Components/SpawnManager.cs +++ b/Library/RSBot.Core/Components/SpawnManager.cs @@ -145,6 +145,9 @@ public static bool TryRemove(uint uniqueId, out SpawnedEntity removedEntity) lock (_lock) { removedEntity = _entities.Find(p => p.UniqueId == uniqueId); + if (removedEntity == null) + return false; + removedEntity.Dispose(); return _entities.Remove(removedEntity); } @@ -284,8 +287,11 @@ public static void Parse(Packet packet, bool isGroup = false) /// public static void Update() { - foreach (var entity in _entities) - entity.Update(); + lock (_lock) + { + foreach (var entity in _entities) + entity.Update(); + } } /// diff --git a/Library/RSBot.Core/Network/Socket/Client.cs b/Library/RSBot.Core/Network/Socket/Client.cs index 273b66bd..94c13b3e 100644 --- a/Library/RSBot.Core/Network/Socket/Client.cs +++ b/Library/RSBot.Core/Network/Socket/Client.cs @@ -228,7 +228,8 @@ private void OnBeginReceiveCallback(IAsyncResult ar) { try { - _socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, OnBeginReceiveCallback, null); + if(_socket.Connected) + _socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, OnBeginReceiveCallback, null); } catch { diff --git a/Library/RSBot.Core/Network/Socket/Server.cs b/Library/RSBot.Core/Network/Socket/Server.cs index 61e0a39e..797b06b7 100644 --- a/Library/RSBot.Core/Network/Socket/Server.cs +++ b/Library/RSBot.Core/Network/Socket/Server.cs @@ -195,8 +195,8 @@ private void ProcessQueuedPackets() foreach (var buffer in _protocol.TransferOutgoing()) { - //if (_socket == null || IsClosing || !EnablePacketProcessor || !_socket.Connected) - //return; + if (_socket == null || IsClosing || !EnablePacketDispatcher || !_socket.Connected) + return; _socket.Send(buffer); }