From a7eaaf43d0094f1e0d629c8ffbedbb4010aa50a8 Mon Sep 17 00:00:00 2001 From: RaphaelIT7 <64648134+RaphaelIT7@users.noreply.github.com> Date: Mon, 17 Nov 2025 07:31:50 +0100 Subject: [PATCH 1/2] engine: reduce CBaseClient size & move scratch buffer --- engine/baseclient.cpp | 5 ++++- engine/baseclient.h | 3 +-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/engine/baseclient.cpp b/engine/baseclient.cpp index 45d61c22a..eb2ad8d00 100644 --- a/engine/baseclient.cpp +++ b/engine/baseclient.cpp @@ -28,6 +28,7 @@ #include "iregistry.h" #include "sv_main.h" #include "hltvserver.h" +#include #ifdef REPLAY_ENABLED #include "replay_internal.h" @@ -1153,7 +1154,9 @@ void CBaseClient::SendSnapshot( CClientFrame *pFrame ) bool bFailedOnce = false; write_again: - bf_write msg( "CBaseClient::SendSnapshot", m_SnapshotScratchBuffer, sizeof( m_SnapshotScratchBuffer ) ); + // RaphaelIT7: Were deep in networking and the stack can easily get close to an overflow + static thread_local std::unique_ptr pSnapshotScratchBuffer(new unsigned int[g_nScratchBufferSize]); + bf_write msg( "CBaseClient::SendSnapshot", pSnapshotScratchBuffer.get(), g_nScratchBufferSize ); TRACE_PACKET( ( "SendSnapshot(%d)\n", pFrame->tick_count ) ); diff --git a/engine/baseclient.h b/engine/baseclient.h index 082ca7c34..3c48521a5 100644 --- a/engine/baseclient.h +++ b/engine/baseclient.h @@ -276,8 +276,7 @@ class CBaseClient : public IGameEventListener2, public IClient, public IClientMe { SNAPSHOT_SCRATCH_BUFFER_SIZE = 160000, }; - - unsigned int m_SnapshotScratchBuffer[ SNAPSHOT_SCRATCH_BUFFER_SIZE / 4 ]; + static constexpr int g_nScratchBufferSize = SNAPSHOT_SCRATCH_BUFFER_SIZE / sizeof(unsigned int); private: void StartTrace( bf_write &msg ); From c74fde1a675826b113a8c4676bc4bdebcb61948d Mon Sep 17 00:00:00 2001 From: RaphaelIT7 <64648134+RaphaelIT7@users.noreply.github.com> Date: Mon, 17 Nov 2025 20:35:28 +0100 Subject: [PATCH 2/2] engine: fix me using the wrong size for the scratch buffer --- engine/baseclient.cpp | 4 ++-- engine/baseclient.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/baseclient.cpp b/engine/baseclient.cpp index eb2ad8d00..0edc6edd6 100644 --- a/engine/baseclient.cpp +++ b/engine/baseclient.cpp @@ -1155,8 +1155,8 @@ void CBaseClient::SendSnapshot( CClientFrame *pFrame ) bool bFailedOnce = false; write_again: // RaphaelIT7: Were deep in networking and the stack can easily get close to an overflow - static thread_local std::unique_ptr pSnapshotScratchBuffer(new unsigned int[g_nScratchBufferSize]); - bf_write msg( "CBaseClient::SendSnapshot", pSnapshotScratchBuffer.get(), g_nScratchBufferSize ); + static thread_local std::unique_ptr pSnapshotScratchBuffer(new unsigned int[g_nScratchBufferSizeAsInt]); + bf_write msg( "CBaseClient::SendSnapshot", pSnapshotScratchBuffer.get(), SNAPSHOT_SCRATCH_BUFFER_SIZE ); TRACE_PACKET( ( "SendSnapshot(%d)\n", pFrame->tick_count ) ); diff --git a/engine/baseclient.h b/engine/baseclient.h index 3c48521a5..299b335d9 100644 --- a/engine/baseclient.h +++ b/engine/baseclient.h @@ -276,7 +276,7 @@ class CBaseClient : public IGameEventListener2, public IClient, public IClientMe { SNAPSHOT_SCRATCH_BUFFER_SIZE = 160000, }; - static constexpr int g_nScratchBufferSize = SNAPSHOT_SCRATCH_BUFFER_SIZE / sizeof(unsigned int); + static constexpr int g_nScratchBufferSizeAsInt = SNAPSHOT_SCRATCH_BUFFER_SIZE / sizeof(unsigned int); private: void StartTrace( bf_write &msg );