From: havoc Date: Sun, 8 Jun 2003 05:47:20 +0000 (+0000) Subject: fix a couple EDICT_NUM errors that often happened when loading savegames with more... X-Git-Tag: xonotic-v0.1.0preview~6591 X-Git-Url: http://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=1d7b31b0dc290650b398e88c376dee1622f0b82d fix a couple EDICT_NUM errors that often happened when loading savegames with more than 256 entities git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3073 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/host_cmd.c b/host_cmd.c index 83edbffc..98d35266 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -600,6 +600,10 @@ void Host_PerformLoadGame(char *name) else { // parse an edict + if (entnum >= MAX_EDICTS) + Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS); + while (entnum >= sv.max_edicts) + SV_IncreaseEdicts(); ent = EDICT_NUM(entnum); memset (ent->v, 0, progs->entityfields * 4); ent->e->free = false; diff --git a/pr_edict.c b/pr_edict.c index b7d34730..83a780e6 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -203,7 +203,6 @@ instead of being removed and recreated, which can cause interpolated angles and bad trails. ================= */ -extern void SV_IncreaseEdicts(void); edict_t *ED_Alloc (void) { int i; @@ -905,7 +904,12 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s) break; case ev_entity: - *(int *)d = EDICT_TO_PROG(EDICT_NUM(atoi (s))); + i = atoi (s); + if (i < 0 || i >= MAX_EDICTS) + Con_DPrintf("ED_ParseEpair: ev_entity reference too large (edict %i >= MAX_EDICTS %i)\n", i, MAX_EDICTS); + while (i >= sv.max_edicts) + SV_IncreaseEdicts(); + *(int *)d = EDICT_TO_PROG(EDICT_NUM(i)); break; case ev_field: @@ -1574,7 +1578,7 @@ void PR_Init (void) // LordHavoc: turned EDICT_NUM into a #define for speed reasons edict_t *EDICT_NUM_ERROR(int n, char *filename, int fileline) { - Host_Error ("EDICT_NUM: bad number %i (called at %f:%i)", n, filename, fileline); + Host_Error ("EDICT_NUM: bad number %i (called at %s:%i)", n, filename, fileline); return NULL; } diff --git a/progs.h b/progs.h index 9fdaffd4..ee5d9e2e 100644 --- a/progs.h +++ b/progs.h @@ -154,6 +154,8 @@ void PR_Profile_f (void); void PR_Crash (void); +void SV_IncreaseEdicts(void); + edict_t *ED_Alloc (void); void ED_Free (edict_t *ed); void ED_ClearEdict (edict_t *e);