sm64coopdx/src/pc/logfile.c
MysterD c88ff19190 Prevent infinite looping of Mario action transitions
There have been several times where the unpredictable behavior of
a remote player where execute_mario_action() would get caught in
an infinite loop. Now we attempt to detect an infinite hang and
escape from it. The sequence of actions will be recorded into an
errorlog.txt file. In debug mode this infinite hang will cause an
assertion to fail, crashing the game. In normal mode the game will
break out of it and hopefully carry on normally after new packets
come in.

I believe this addresses github issue #12 but I can't be sure.
2020-09-01 22:06:36 -07:00

40 lines
No EOL
807 B
C

// logfile.c - handles opening and closing of the log file
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#define LOGFILE_NAME "errorlog.txt"
static bool firstOpen = true;
static bool active = false;
static FILE* logfile = NULL;
bool logfile_open(FILE** f) {
if (active) {
*f = logfile;
return true;
}
printf("Initiating logfile to '%s'\n", LOGFILE_NAME);
logfile = fopen(fs_get_write_path(LOGFILE_NAME), "a");
if (logfile == NULL) { return false; }
*f = logfile;
if (firstOpen) {
fprintf(logfile, "--- new run ---\n");
firstOpen = false;
}
active = true;
return logfile;
}
void logfile_close(void) {
if (!active) { return; }
fflush(logfile);
fclose(logfile);
active = false;
}