Skip to content

Commit

Permalink
Fix -levelstat command (#1249)
Browse files Browse the repository at this point in the history
Close file stream in G_WriteLevelStat function.
  • Loading branch information
rfomin authored Dec 23, 2024
1 parent 9317be8 commit 27ea096
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/doom/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ static void G_FormatLevelStatTime(char *str, int tics)
// [crispy] Write level statistics upon exit
static void G_WriteLevelStat(void)
{
static FILE *fstream = NULL;
FILE *fstream;

int i, playerKills = 0, playerItems = 0, playerSecrets = 0;

Expand All @@ -1994,15 +1994,22 @@ static void G_WriteLevelStat(void)
char totalTimeString[TIMESTRSIZE];
char *decimal;

if (fstream == NULL)
static boolean firsttime = true;

if (firsttime)
{
fstream = fopen("levelstat.txt", "w");
firsttime = false;
fstream = M_fopen("levelstat.txt", "w");
}
else
{
fstream = M_fopen("levelstat.txt", "a");
}

if (fstream == NULL)
{
fprintf(stderr, "G_WriteLevelStat: Unable to open levelstat.txt for writing!\n");
return;
}
if (fstream == NULL)
{
fprintf(stderr, "G_WriteLevelStat: Unable to open levelstat.txt for writing!\n");
return;
}

if (gamemode == commercial)
Expand Down Expand Up @@ -2039,6 +2046,8 @@ static void G_WriteLevelStat(void)
levelString, (secretexit ? "s" : ""),
levelTimeString, totalTimeString, playerKills, totalkills,
playerItems, totalitems, playerSecrets, totalsecret);

fclose(fstream);
}

void G_DoCompleted (void)
Expand Down

0 comments on commit 27ea096

Please sign in to comment.