]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Initialize globalindex for autocvars with -1 to prevent prog corruption.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 7 Feb 2016 01:53:16 +0000 (01:53 +0000)
committerRudolf Polzer <divVerent@xonotic.org>
Fri, 4 Mar 2016 21:01:19 +0000 (22:01 +0100)
From: Grigorii Kasymov <kasymovga@xsmail.com>

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12242 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=bcc992065b8e58eda2dca44952c15e862537978e

cvar.c
prvm_edict.c

diff --git a/cvar.c b/cvar.c
index 5ae8e521c53b6daf2231ceda3732606b1edbdecc..d34378a0c46aad1c053479050761cc54034b5060 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -270,7 +270,7 @@ static qboolean Cvar_IsAutoCvar(cvar_t *var)
        for (i = 0;i < PRVM_PROG_MAX;i++)
        {
                prog = &prvm_prog_list[i];
-               if (prog->loaded && var->globaldefindex_progid[i] == prog->id)
+               if (prog->loaded && var->globaldefindex_progid[i] == prog->id && var->globaldefindex[i] >= 0)
                        return true;
        }
        return false;
@@ -287,7 +287,7 @@ static void Cvar_UpdateAutoCvar(cvar_t *var)
        for (i = 0;i < PRVM_PROG_MAX;i++)
        {
                prog = &prvm_prog_list[i];
-               if (prog->loaded && var->globaldefindex_progid[i] == prog->id)
+               if (prog->loaded && var->globaldefindex_progid[i] == prog->id && var->globaldefindex[i] >= 0)
                {
                        // MUST BE SYNCED WITH prvm_edict.c PRVM_LoadProgs
                        switch(prog->globaldefs[var->globaldefindex[i]].type & ~DEF_SAVEGLOBAL)
index 77a1af71b053f5a9143496359961f2fb2c8e4684..6500b341e23004b0d80bc4f5821ca2ed4c241b21 100644 (file)
@@ -1938,6 +1938,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da
        unsigned int d;
        char vabuf[1024];
        char vabuf2[1024];
+       cvar_t *cvar;
 
        if (prog->loaded)
                prog->error_cmd("PRVM_LoadProgs: there is already a %s program loaded!", prog->name );
@@ -2353,6 +2354,9 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da
                }
        }
 
+       for (cvar = cvar_vars; cvar; cvar = cvar->next)
+               cvar->globaldefindex[prog - prvm_prog_list] = -1;
+
        for (i=0 ; i<prog->numglobaldefs ; i++)
        {
                const char *name;
@@ -2364,7 +2368,7 @@ void PRVM_Prog_Load(prvm_prog_t *prog, const char * filename, unsigned char * da
                )
                {
                        prvm_eval_t *val = PRVM_GLOBALFIELDVALUE(prog->globaldefs[i].ofs);
-                       cvar_t *cvar = Cvar_FindVar(name + 9);
+                       cvar = Cvar_FindVar(name + 9);
                        //Con_Printf("PRVM_LoadProgs: autocvar global %s in %s, processing...\n", name, prog->name);
                        if(!cvar)
                        {