mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-30 08:00:51 +00:00
- add a NUM_FOR_BAD_EDICT function, which doesn't care if it's a bad
value - switch some prints over NUM_FOR_BAD_EDICT - change NUM_FOR_EDICT to call PR_RunError on error, instead of PR_Error. That was it prints out a backtrace. (I did it in reverse order ;)
This commit is contained in:
parent
a159e852e6
commit
07b0d91900
3 changed files with 19 additions and 7 deletions
|
@ -107,6 +107,7 @@ int PR_AccessField (progs_t *pr, const char *name, etype_t type,
|
|||
|
||||
edict_t *EDICT_NUM(progs_t *pr, int n);
|
||||
int NUM_FOR_EDICT(progs_t *pr, edict_t *e);
|
||||
int NUM_FOR_BAD_EDICT(progs_t *pr, edict_t *e);
|
||||
|
||||
#define NEXT_EDICT(p,e) ((edict_t *)( (byte *)e + (p)->pr_edict_size))
|
||||
|
||||
|
|
|
@ -361,7 +361,7 @@ PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val)
|
|||
break;
|
||||
case ev_entity:
|
||||
snprintf (line, sizeof (line), "entity %i",
|
||||
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
||||
NUM_FOR_BAD_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
||||
break;
|
||||
case ev_func:
|
||||
f = pr->pr_functions + val->func_var;
|
||||
|
@ -425,7 +425,7 @@ PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val)
|
|||
break;
|
||||
case ev_entity:
|
||||
snprintf (line, sizeof (line), "%i",
|
||||
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
||||
NUM_FOR_BAD_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
|
||||
break;
|
||||
case ev_func:
|
||||
f = pr->pr_functions + val->func_var;
|
||||
|
@ -544,7 +544,7 @@ ED_Print (progs_t * pr, edict_t *ed)
|
|||
return;
|
||||
}
|
||||
|
||||
Sys_Printf ("\nEDICT %i:\n", NUM_FOR_EDICT (pr, ed));
|
||||
Sys_Printf ("\nEDICT %i:\n", NUM_FOR_BAD_EDICT (pr, ed));
|
||||
for (i = 1; i < pr->progs->numfielddefs; i++) {
|
||||
d = &pr->pr_fielddefs[i];
|
||||
name = PR_GetString (pr, d->s_name);
|
||||
|
@ -1459,20 +1459,31 @@ EDICT_NUM (progs_t * pr, int n)
|
|||
{
|
||||
int offs = n * pr->pr_edict_size;
|
||||
if (offs < 0 || n >= pr->pr_edictareasize)
|
||||
PR_Error (pr, "EDICT_NUM: bad number %i", n);
|
||||
PR_RunError (pr, "EDICT_NUM: bad number %i", n);
|
||||
return PROG_TO_EDICT (pr, offs);
|
||||
}
|
||||
|
||||
int
|
||||
NUM_FOR_EDICT (progs_t * pr, edict_t *e)
|
||||
NUM_FOR_BAD_EDICT (progs_t *pr, edict_t *e)
|
||||
{
|
||||
int b;
|
||||
|
||||
b = (byte *) e - (byte *) * (pr)->edicts;
|
||||
b = b / pr->pr_edict_size;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
int
|
||||
NUM_FOR_EDICT (progs_t *pr, edict_t *e)
|
||||
{
|
||||
int b;
|
||||
|
||||
b = NUM_FOR_BAD_EDICT (pr, e);
|
||||
|
||||
if (b && (b < 0 || b >= *(pr)->num_edicts))
|
||||
PR_Error (pr, "NUM_FOR_EDICT: bad pointer %d %p %p", b, e, * (pr)->edicts);
|
||||
PR_RunError (pr, "NUM_FOR_EDICT: bad pointer %d %p %p", b, e, * (pr)->edicts);
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ PR_ExecuteProgram (progs_t * pr, func_t fnum)
|
|||
if (!fnum || fnum >= pr->progs->numfunctions) {
|
||||
if (*pr->globals.self)
|
||||
ED_Print (pr, PROG_TO_EDICT (pr, *pr->globals.self));
|
||||
PR_Error (pr, "PR_ExecuteProgram: NULL function");
|
||||
PR_RunError (pr, "PR_ExecuteProgram: NULL function");
|
||||
}
|
||||
|
||||
f = &pr->pr_functions[fnum];
|
||||
|
|
Loading…
Reference in a new issue