summaryrefslogtreecommitdiff
path: root/src/common/common.c
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2014-12-03 13:28:16 +0300
committerAndrey Nazarov <skuller@skuller.net>2014-12-03 18:33:25 +0300
commit924ff39aa48df1d6cd985b42a2fe5a60ff154030 (patch)
tree79dc211425cf4689ec56308fb93c4f4bbc17d464 /src/common/common.c
parent7525450fb6d79d7371375d7f710ba4fe484494b3 (diff)
Stop fiddling around with jmp_buf.
Implement custom abort function handler for cleaning up CM after failed server startup. Less hacky and more portable than previous solution that involved swapping copies of jmp_buf around. Fixes a weird Win64 crash when loading savegames.
Diffstat (limited to 'src/common/common.c')
-rw-r--r--src/common/common.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/common/common.c b/src/common/common.c
index 48a82ea..a136c43 100644
--- a/src/common/common.c
+++ b/src/common/common.c
@@ -49,7 +49,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "server/server.h"
#include "system/system.h"
-jmp_buf com_abortframe; // an ERR_DROP occured, exit the entire frame
+#include <setjmp.h>
+
+static jmp_buf com_abortframe; // an ERR_DROP occured, exit the entire frame
+
+static void (*com_abort_func)(void *);
+static void *com_abort_arg;
static qboolean com_errorEntered;
static char com_errorMsg[MAXERRORMSG]; // from Com_Printf/Com_Error
@@ -509,6 +514,12 @@ void Com_Error(error_type_t code, const char *fmt, ...)
// abort any console redirects
Com_AbortRedirect();
+ // call custom cleanup function if set
+ if (com_abort_func) {
+ com_abort_func(com_abort_arg);
+ com_abort_func = NULL;
+ }
+
// reset Com_Printf recursion level
com_printEntered = 0;
@@ -562,6 +573,12 @@ abort:
longjmp(com_abortframe, -1);
}
+void Com_AbortFunc(void (*func)(void *), void *arg)
+{
+ com_abort_func = func;
+ com_abort_arg = arg;
+}
+
#ifdef _WIN32
void Com_AbortFrame(void)
{