Skip to content

Commit

Permalink
Don't try to write to the log file if it didn't open.
Browse files Browse the repository at this point in the history
  • Loading branch information
bolrog committed May 17, 2021
1 parent 47605bc commit a6e964f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/d2dx/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,18 @@ WindowsVersion d2dx::GetActualWindowsVersion()
}

static bool logFileOpened = false;
static FILE* logFile = 0;
static FILE* logFile = nullptr;
static CRITICAL_SECTION logFileCS;

static void EnsureLogFileOpened()
{
if (!logFileOpened)
{
logFileOpened = true;
fopen_s(&logFile, "d2dx_log.txt", "w");
if (fopen_s(&logFile, "d2dx_log.txt", "w") != 0)
{
logFile = nullptr;
}
InitializeCriticalSection(&logFileCS);
}
}
Expand All @@ -134,8 +137,11 @@ static DWORD WINAPI WriteToLogFileWorkItemFunc(PVOID pvContext)

EnterCriticalSection(&logFileCS);

fwrite(s, strlen(s), 1, logFile);
fflush(logFile);
if (logFile)
{
fwrite(s, strlen(s), 1, logFile);
fflush(logFile);
}

LeaveCriticalSection(&logFileCS);

Expand Down Expand Up @@ -175,6 +181,7 @@ Buffer<char> d2dx::ReadTextFile(
{
Buffer<char> str(1);
str.items[0] = 0;
fclose(cfgFile);
return str;
}

Expand Down

0 comments on commit a6e964f

Please sign in to comment.