@@ -32,9 +32,7 @@ namespace ModAPI
3232 static constexpr unsigned int SCRATCH_SIZE = 4096 ;
3333 char logScratch[SCRATCH_SIZE ];
3434
35- void Log (const char * fmt, ...) {
36- unsigned int offset = 0 ;
37-
35+ void Log (const char * fmt, ...) {
3836 __time64_t long_time;
3937 _time64 (&long_time);
4038
@@ -47,25 +45,31 @@ namespace ModAPI
4745 const int mins = long_time % 60 ;
4846 long_time /= 60 ;
4947 const int hours = long_time % 24 ;
48+
49+ logFileMutex.lock ();
5050
51- sprintf_s (logScratch + offset , SCRATCH_SIZE - offset , format, hours,mins,secs);
52- offset + = (sizeof (formatted)-1 )/sizeof (formatted[0 ]);
51+ sprintf_s (logScratch, SCRATCH_SIZE , format, hours,mins,secs);
52+ unsigned int time_offset = (sizeof (formatted)-1 )/sizeof (formatted[0 ]);
5353
5454 va_list argList;
5555 va_start (argList, fmt);
56- vsnprintf (logScratch + offset , SCRATCH_SIZE - offset , fmt, argList);
56+ vsnprintf (logScratch + time_offset , SCRATCH_SIZE - time_offset , fmt, argList);
5757 va_end (argList);
5858
5959 // vsnprintf does not guarantee a null terminator if the formatted string exceeds the buffer size
6060 logScratch[SCRATCH_SIZE - 1 ] = 0 ;
6161
62+ auto log_len = strlen (logScratch);
63+
6264 if (logFile)
6365 {
64- logFile->Write (logScratch, strlen (logScratch) );
66+ logFile->Write (logScratch, log_len );
6567 logFile->Write (" \n " , 1 );
6668 logFile->Flush ();
6769 }
68- App::ConsolePrintF (logScratch + offset);
70+ App::ConsolePrintF (logScratch + time_offset);
71+ memset (logScratch, 0 , log_len);
72+ logFileMutex.unlock ();
6973 }
7074
7175 bool AddSimulatorStrategy (Simulator::ISimulatorStrategy* strategy, uint32_t id) {
0 commit comments