From 97703839c970c295ba6173da463906bdec6d55cd Mon Sep 17 00:00:00 2001 From: divverent Date: Tue, 6 Aug 2013 13:40:35 +0000 Subject: [PATCH] In prog reset functions, do not call functions unless prog->loaded. This fixes segfaults in case progs loading itself may have caused Host_Error. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11995 d7cf8633-e32d-0410-b094-e92efae38249 --- csprogs.c | 11 +++++++---- menu.c | 4 ++-- svvm_cmds.c | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/csprogs.c b/csprogs.c index 36cecf83..fa5e690b 100644 --- a/csprogs.c +++ b/csprogs.c @@ -1160,10 +1160,13 @@ void CL_VM_ShutDown (void) if(!cl.csqc_loaded) return; CSQC_BEGIN - PRVM_clientglobalfloat(time) = cl.time; - PRVM_clientglobaledict(self) = 0; - if (PRVM_clientfunction(CSQC_Shutdown)) - prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Shutdown), "QC function CSQC_Shutdown is missing"); + if (prog->loaded) + { + PRVM_clientglobalfloat(time) = cl.time; + PRVM_clientglobaledict(self) = 0; + if (PRVM_clientfunction(CSQC_Shutdown)) + prog->ExecuteProgram(prog, PRVM_clientfunction(CSQC_Shutdown), "QC function CSQC_Shutdown is missing"); + } PRVM_Prog_Reset(prog); CSQC_END Con_DPrint("CSQC ^1unloaded\n"); diff --git a/menu.c b/menu.c index 34a8de7f..d1311ca3 100644 --- a/menu.c +++ b/menu.c @@ -5333,8 +5333,8 @@ static void MP_NewMap(void) static void MP_Shutdown (void) { prvm_prog_t *prog = MVM_prog; - - prog->ExecuteProgram(prog, PRVM_menufunction(m_shutdown),"m_shutdown() required"); + if (prog->loaded) + prog->ExecuteProgram(prog, PRVM_menufunction(m_shutdown),"m_shutdown() required"); // reset key_dest key_dest = key_game; diff --git a/svvm_cmds.c b/svvm_cmds.c index e9d51fdf..c75dd077 100644 --- a/svvm_cmds.c +++ b/svvm_cmds.c @@ -3835,7 +3835,8 @@ void SVVM_init_cmd(prvm_prog_t *prog) void SVVM_reset_cmd(prvm_prog_t *prog) { World_End(&sv.world); - if(PRVM_serverfunction(SV_Shutdown)) + + if(prog->loaded && PRVM_serverfunction(SV_Shutdown)) { func_t s = PRVM_serverfunction(SV_Shutdown); PRVM_serverglobalfloat(time) = sv.time; -- 2.39.2