]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - prvm_exec.c
fix an uninitialized variable
[xonotic/darkplaces.git] / prvm_exec.c
index eab6a2fdf2e51d2d9851dafd376d47b96bd6f926..7481114822f751e2948290990a8ca322f7ff11f8 100644 (file)
@@ -363,7 +363,8 @@ void PRVM_PrintState(void)
        PRVM_StackTrace ();
 }
 
-void PRVM_Crash()
+extern sizebuf_t vm_tempstringsbuf;
+void PRVM_Crash(void)
 {
        if (prog == NULL)
                return;
@@ -378,6 +379,9 @@ void PRVM_Crash()
        prog->depth = 0;
        prog->localstack_used = 0;
 
+       // delete all tempstrings (FIXME: is this safe in VM->engine->VM recursion?)
+       vm_tempstringsbuf.cursize = 0;
+
        // reset the prog pointer
        prog = NULL;
 }
@@ -484,8 +488,7 @@ PRVM_ExecuteProgram
 extern cvar_t prvm_boundscheck;
 extern cvar_t prvm_traceqc;
 extern cvar_t prvm_statementprofiling;
-extern int             PRVM_ED_FindFieldOffset (const char *field);
-extern ddef_t* PRVM_ED_FindGlobal(const char *name);
+extern sizebuf_t vm_tempstringsbuf;
 void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
 {
        dstatement_t    *st, *startst;
@@ -493,16 +496,20 @@ void PRVM_ExecuteProgram (func_t fnum, const char *errormessage)
        prvm_edict_t    *ed;
        prvm_eval_t     *ptr;
        int             jumpcount, cachedpr_trace, exitdepth;
+       int             restorevm_tempstringsbuf_cursize;
 
        if (!fnum || fnum >= (unsigned int)prog->progs->numfunctions)
        {
-               if (prog->self && PRVM_G_INT(prog->self->ofs))
-                       PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_G_INT(prog->self->ofs)));
+               if (prog->globaloffsets.self >= 0 && PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict)
+                       PRVM_ED_Print(PRVM_PROG_TO_EDICT(PRVM_GLOBALFIELDVALUE(prog->globaloffsets.self)->edict));
                PRVM_ERROR ("PRVM_ExecuteProgram: %s", errormessage);
        }
 
        f = &prog->functions[fnum];
 
+       // after executing this function, delete all tempstrings it created
+       restorevm_tempstringsbuf_cursize = vm_tempstringsbuf.cursize;
+
        prog->trace = prvm_traceqc.integer;
 
        // we know we're done when pr_depth drops to this
@@ -585,4 +592,10 @@ chooseexecprogram:
                        }
                }
        }
+
+cleanup:
+       if (developer.integer >= 200 && vm_tempstringsbuf.cursize > restorevm_tempstringsbuf_cursize)
+               Con_Printf("PRVM_ExecuteProgram: %s used %i bytes of tempstrings\n", PRVM_GetString(prog->functions[fnum].s_name), vm_tempstringsbuf.cursize - restorevm_tempstringsbuf_cursize);
+       // delete tempstrings created by this function
+       vm_tempstringsbuf.cursize = restorevm_tempstringsbuf_cursize;
 }