fix a couple EDICT_NUM errors that often happened when loading savegames with more...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 8 Jun 2003 05:47:20 +0000 (05:47 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 8 Jun 2003 05:47:20 +0000 (05:47 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@3073 d7cf8633-e32d-0410-b094-e92efae38249

host_cmd.c
pr_edict.c
progs.h

index 83edbff..98d3526 100644 (file)
@@ -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;
index b7d3473..83a780e 100644 (file)
@@ -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 9fdaffd..ee5d9e2 100644 (file)
--- 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);