From 642dc1ea5e74a3d6a717d0ba4ceca8e48c405915 Mon Sep 17 00:00:00 2001 From: smatz Date: Sat, 7 Mar 2009 22:40:47 +0000 Subject: (svn r15640) -Fix [FS#2712]: game crashes when network pools are empty, so always allocate at least one pool block --- src/network/network.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/network') diff --git a/src/network/network.cpp b/src/network/network.cpp index 97ac48d35..542d4f52c 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -591,12 +591,18 @@ static bool NetworkListen() return true; } +/** Resets both pools used for network clients */ +static void InitializeNetworkPools() +{ + _NetworkClientSocket_pool.CleanPool(); + _NetworkClientSocket_pool.AddBlockToPool(); + _NetworkClientInfo_pool.CleanPool(); + _NetworkClientInfo_pool.AddBlockToPool(); +} + // Close all current connections static void NetworkClose() { - /* The pool is already empty, so we already closed the connections */ - if (GetNetworkClientSocketPoolSize() == 0) return; - NetworkClientSocket *cs; FOR_ALL_CLIENT_SOCKETS(cs) { @@ -625,17 +631,13 @@ static void NetworkClose() free(_network_company_states); _network_company_states = NULL; - _NetworkClientSocket_pool.CleanPool(); - _NetworkClientInfo_pool.CleanPool(); + InitializeNetworkPools(); } // Inits the network (cleans sockets and stuff) static void NetworkInitialize() { - _NetworkClientSocket_pool.CleanPool(); - _NetworkClientSocket_pool.AddBlockToPool(); - _NetworkClientInfo_pool.CleanPool(); - _NetworkClientInfo_pool.AddBlockToPool(); + InitializeNetworkPools(); _sync_frame = 0; _network_first_time = true; -- cgit v1.2.3-70-g09d2