In prog reset functions, do not call functions unless prog->loaded.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 6 Aug 2013 13:40:35 +0000 (13:40 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Tue, 6 Aug 2013 13:40:35 +0000 (13:40 +0000)
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
menu.c
svvm_cmds.c

index 36cecf8..fa5e690 100644 (file)
--- 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 34a8de7..d1311ca 100644 (file)
--- 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;
index e9d51fd..c75dd07 100644 (file)
@@ -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;