From: divverent Date: Sun, 7 Feb 2016 01:53:16 +0000 (+0000) Subject: Initialize globalindex for autocvars with -1 to prevent prog corruption. X-Git-Tag: xonotic-v0.8.2~56 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b5a8a6ff058033417f5a094a41d1f56887675d05;p=xonotic%2Fdarkplaces.git Initialize globalindex for autocvars with -1 to prevent prog corruption. From: Grigorii Kasymov git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12242 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=bcc992065b8e58eda2dca44952c15e862537978e --- diff --git a/cvar.c b/cvar.c index 5ae8e521..d34378a0 100644 --- 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) diff --git a/prvm_edict.c b/prvm_edict.c index 77a1af71..6500b341 100644 --- a/prvm_edict.c +++ b/prvm_edict.c @@ -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 ; inumglobaldefs ; 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) {