mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2025-12-08 09:02:41 +00:00
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.
40 lines
No EOL
807 B
C
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;
|
|
} |