diff options
author | smatz <smatz@openttd.org> | 2009-03-07 22:40:47 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-03-07 22:40:47 +0000 |
commit | 642dc1ea5e74a3d6a717d0ba4ceca8e48c405915 (patch) | |
tree | 4f14d818719475edf6fc40b70ff777e1e90a9d31 | |
parent | 3f73152b7fb810f57a6d4048c484b13aad6c51b3 (diff) | |
download | openttd-642dc1ea5e74a3d6a717d0ba4ceca8e48c405915.tar.xz |
(svn r15640) -Fix [FS#2712]: game crashes when network pools are empty, so always allocate at least one pool block
-rw-r--r-- | src/network/network.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
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; |