Skip to content

Commit 0eee1ec

Browse files
authored
Fix server crash when auto recording server-side (#1882)
The guess from the crashdump: the server trying to use VGUI global var which may not be initialized for the server and get nullptr deref. Change how datetime is fetched to a stdlib way.
1 parent 8c898f0 commit 0eee1ec

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/game/shared/neo/neo_misc.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
#ifdef CLIENT_DLL
44
#include "steamclientpublic.h"
5+
#include "vgui/ISystem.h"
56
#endif // CLIENT_DLL
67
#include "cbase.h"
78
#include "neo_gamerules.h"
8-
#include "vgui/ISystem.h"
99
#include "tier3.h"
1010
#include <filesystem.h>
11+
#include <ctime>
1112

1213
extern ConVar sv_neo_comp_name;
1314

@@ -88,9 +89,10 @@ bool StartAutoRecording()
8889

8990
// Time and date
9091
char timeSection[16];
91-
int year, month, dayOfWeek, day, hour, minute, second;
92-
g_pVGuiSystem->GetCurrentTimeAndDate(&year, &month, &dayOfWeek, &day, &hour, &minute, &second);
93-
V_snprintf(timeSection, sizeof(timeSection), "%04d%02d%02d-%02d%02d", year, month, day, hour, minute);
92+
const time_t timeVal = time(nullptr);
93+
std::tm tmStruct{};
94+
std::tm tmd = *(Plat_localtime(&timeVal, &tmStruct));
95+
V_sprintf_safe(timeSection, "%04d%02d%02d-%02d%02d", tmd.tm_year + 1900, tmd.tm_mon + 1, tmd.tm_mday, tmd.tm_hour, tmd.tm_min);
9496

9597
// Competition name
9698
char compSection[32];
@@ -128,4 +130,4 @@ bool StartAutoRecording()
128130
engine->ServerCommand(UTIL_VarArgs("tv_stoprecord;tv_record \"%s/%s\";\n", DEMOS_DIRECTORY_NAME, replayName));
129131
return true; // hopefully we're recording. Last line of tv_status prints if a demo is being recorded but don't see how to get at that value here
130132
#endif // CLIENT_DLL
131-
}
133+
}

0 commit comments

Comments
 (0)