Skip to content

Commit aa6d21b

Browse files
Merge pull request #688 from themuffinator/codex/investigate-and-resolve-crash-issue
Initialize lag compensation buffers
2 parents 1f05f21 + 1a8159d commit aa6d21b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/server/gameplay/g_clients.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ g_clients.cpp implementation.*/
77

88
#include <algorithm>
99
#include <cstddef>
10+
#include <new>
1011

1112
namespace {
1213
int ClampMaxClients(int maxClients) {
@@ -65,6 +66,9 @@ void AllocateClientArray(int maxClients) {
6566
const std::size_t lagCount = static_cast<std::size_t>(game.maxClients) * static_cast<std::size_t>(game.maxLagOrigins);
6667
game.lagOrigins = static_cast<Vector3*>(TagMallocChecked(sizeof(Vector3) * lagCount));
6768

69+
for (std::size_t i = 0; i < lagCount; ++i)
70+
new (&game.lagOrigins[i]) Vector3();
71+
6872
// [KEX]: Ensure client pointers are linked immediately to prevent engine crashes
6973
// if SV_CalcPings runs before a client is fully connected.
7074
if (g_entities) {
@@ -86,6 +90,14 @@ void FreeClientArray() {
8690
DestroyClients(game.clients, game.maxClients);
8791

8892
TagFreeChecked(game.clients);
93+
94+
if (game.lagOrigins) {
95+
const std::size_t lagCount = static_cast<std::size_t>(game.maxClients) * static_cast<std::size_t>(game.maxLagOrigins);
96+
97+
for (std::size_t i = 0; i < lagCount; ++i)
98+
game.lagOrigins[i].~Vector3();
99+
}
100+
89101
TagFreeChecked(game.lagOrigins);
90102

91103
game.clients = nullptr;

0 commit comments

Comments
 (0)