Inreased debugging level for catching oob accesses to 'main' arrays.

If enabled, this makes the following arrays be allocated statically:
spriteext, spritesmooth, sector, wall, sprite, tsprite, while
necessarily disabling the clipshape feature (because it relies on
setting sector/wall to different malloc'd block temporarily).

To compile, pass DEBUGANYWAY=1 in addition to RELEASE=0 to 'make',
and it's really only useful with CC=clang, of course.

git-svn-id: https://svn.eduke32.com/eduke32@2270 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-01-19 23:17:34 +00:00
parent ba25d9a678
commit d0acd40ff8
7 changed files with 103 additions and 27 deletions

View file

@ -92,7 +92,13 @@ ifneq (0,$(RELEASE))
endif
else
# Debugging enabled
debug=-ggdb -O0 -DDEBUGGINGAIDS
debug=-ggdb -O0
ifeq (0,$(DEBUGANYWAY))
debug+= -DDEBUGGINGAIDS
else
debug+= -DDEBUGGINGAIDS=2
endif
ifeq ($(CC),clang)
debug+= -fcatch-undefined-behavior
endif

View file

@ -264,20 +264,31 @@ typedef struct {
#define SPREXT_TSPRACCESS 16
#define SPREXT_TEMPINVISIBLE 32
EXTERN int32_t guniqhudid;
EXTERN int32_t spritesortcnt;
#if !defined DEBUG_MAIN_ARRAYS
EXTERN spriteext_t *spriteext;
EXTERN spritesmooth_t *spritesmooth;
EXTERN int32_t guniqhudid;
EXTERN sectortype *sector;
EXTERN walltype *wall;
EXTERN spritetype *sprite;
EXTERN spritetype *tsprite;
#else
EXTERN spriteext_t spriteext[MAXSPRITES+MAXUNIQHUDID];
EXTERN spritesmooth_t spritesmooth[MAXSPRITES+MAXUNIQHUDID];
EXTERN sectortype sector[MAXSECTORS + M32_FIXME_SECTORS];
EXTERN walltype wall[MAXWALLS + M32_FIXME_WALLS];
EXTERN spritetype sprite[MAXSPRITES];
EXTERN spritetype tsprite[MAXSPRITESONSCREEN];
#endif
EXTERN int16_t maskwall[MAXWALLSB], maskwallcnt;
EXTERN int16_t thewall[MAXWALLSB];
EXTERN spritetype *sprite;
EXTERN spritetype *tspriteptr[MAXSPRITESONSCREEN + 1];
EXTERN int32_t spritesortcnt;
EXTERN spritetype *tsprite;
EXTERN int32_t xdim, ydim, numpages;
EXTERN int32_t yxaspect, viewingrange;
EXTERN intptr_t ylookup[MAXYDIM+1];
@ -534,7 +545,9 @@ void initspritelists(void);
int32_t loadboard(char *filename, char flags, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum);
int32_t loadmaphack(const char *filename);
void delete_maphack_lights();
#if !defined DEBUG_MAIN_ARRAYS
int32_t clipmapinfo_load(const char *filename);
#endif
int32_t saveboard(const char *filename, int32_t *daposx, int32_t *daposy, int32_t *daposz, int16_t *daang, int16_t *dacursectnum);
int32_t loadpics(const char *filename, int32_t askedsize);
void loadtile(int16_t tilenume);

View file

@ -122,6 +122,10 @@ static inline float nearbyintf(float x)
# define NULL ((void *)0)
#endif
#if DEBUGGINGAIDS>=2
# define DEBUG_MAIN_ARRAYS
#endif
// redefined for apple/ppc, which chokes on stderr when linking...
#define ERRprintf(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)

View file

@ -585,9 +585,11 @@ int32_t app_main(int32_t argc, const char **argv)
// Here used to be the 'whitecol' calculation
#if !defined DEBUG_MAIN_ARRAYS
k = clipmapinfo_load("_clipshape0.map");
if (k>0)
initprintf("There was an error loading the sprite clipping map (status %d).\n", k);
#endif
taglab_init();

View file

@ -49,6 +49,10 @@
#define CACHEAGETIME 16
#if !defined DEBUG_MAIN_ARRAYS
# define HAVE_CLIPSHAPE_FEATURE
#endif
float debug1, debug2;
static void drawpixel_safe(void *s, char a)
@ -1110,6 +1114,7 @@ static vec3_t m32_viewplane;
////// sector-like clipping for sprites //////
#ifdef HAVE_CLIPSHAPE_FEATURE
typedef struct
{
int16_t numsectors, numwalls;
@ -1644,7 +1649,7 @@ int32_t clipmapinfo_load(const char *filename)
return 0;
}
#endif
////// //////
#define WALLS_ARE_CONSISTENT(k) ((wall[k].x == x2 && wall[k].y == y2) \
@ -7676,12 +7681,14 @@ static int32_t preinitcalled = 0;
// #define DYNALLOC_ARRAYS
#ifndef DYNALLOC_ARRAYS
# if !defined DEBUG_MAIN_ARRAYS
static spriteext_t spriteext_s[MAXSPRITES+MAXUNIQHUDID];
static spritesmooth_t spritesmooth_s[MAXSPRITES+MAXUNIQHUDID];
static sectortype sector_s[MAXSECTORS + M32_FIXME_SECTORS];
static walltype wall_s[MAXWALLS + M32_FIXME_WALLS];
static spritetype sprite_s[MAXSPRITES];
static spritetype tsprite_s[MAXSPRITESONSCREEN];
# endif
#else
void *blockptr = NULL;
#endif
@ -7739,12 +7746,14 @@ int32_t preinitengine(void)
}
#else
# if !defined DEBUG_MAIN_ARRAYS
sector = sector_s;
wall = wall_s;
sprite = sprite_s;
tsprite = tsprite_s;
spriteext = spriteext_s;
spritesmooth = spritesmooth_s;
# endif
state_compress = (qlz_state_compress *) Bcalloc(sizeof(qlz_state_compress) + sizeof(qlz_state_decompress), 1);
state_decompress = (qlz_state_decompress *)((int8_t *)(state_compress) + sizeof(qlz_state_compress));
#endif
@ -7761,9 +7770,9 @@ int32_t preinitengine(void)
getvalidmodes();
initcrc32table();
#ifdef HAVE_CLIPSHAPE_FEATURE
clipmapinfo_init();
#endif
preinitcalled = 1;
return 0;
}
@ -9014,7 +9023,9 @@ int32_t loadboard(char *filename, char flags, int32_t *daposx, int32_t *daposy,
kclose(fil);
#ifdef HAVE_CLIPSHAPE_FEATURE
if (!quickloadboard)
#endif
{
Bmemset(spriteext, 0, sizeof(spriteext_t) * MAXSPRITES);
@ -10985,6 +10996,7 @@ static int32_t hitscan_trysector(const vec3_t *sv, const sectortype *sec, hitdat
hitinfo->pos.x = x1; hitinfo->pos.y = y1; hitinfo->pos.z = z1;
}
}
#ifdef HAVE_CLIPSHAPE_FEATURE
else
{
for (i=clipinfo[curidx].qbeg; i<clipinfo[curidx].qend; i++)
@ -10997,6 +11009,7 @@ static int32_t hitscan_trysector(const vec3_t *sv, const sectortype *sec, hitdat
}
}
}
#endif
}
}
@ -11047,6 +11060,7 @@ restart_grand:
clipspritecnt = clipspritenum = 0;
do
{
#ifdef HAVE_CLIPSHAPE_FEATURE
if (tempshortcnt >= tempshortnum)
{
// one bunch of sectors completed, prepare the next
@ -11077,10 +11091,11 @@ restart_grand:
tempshortnum = (int16_t)clipsectnum;
tempshortcnt = 0;
}
#endif
dasector = clipsectorlist[tempshortcnt]; sec = &sector[dasector];
i = 1;
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
{
if (dasector == sectq[clipinfo[curidx].qend])
@ -11090,7 +11105,7 @@ restart_grand:
}
else tmp[2] = 0;
}
#endif
if (hitscan_trysector(sv, sec, hitinfo, vx,vy,vz, sec->ceilingstat, sec->ceilingheinum, sec->ceilingz, -i, tmpptr))
continue;
if (hitscan_trysector(sv, sec, hitinfo, vx,vy,vz, sec->floorstat, sec->floorheinum, sec->floorz, i, tmpptr))
@ -11127,6 +11142,7 @@ restart_grand:
continue;
}
}
#ifdef HAVE_CLIPSHAPE_FEATURE
else
{
int32_t cz,fz;
@ -11147,15 +11163,15 @@ restart_grand:
continue;
}
}
#endif
for (zz=tempshortnum-1; zz>=0; zz--)
if (clipsectorlist[zz] == nextsector) break;
if (zz < 0) clipsectorlist[tempshortnum++] = nextsector;
}
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
continue;
#endif
for (z=headspritesect[dasector]; z>=0; z=nextspritesect[z])
{
spr = &sprite[z];
@ -11165,6 +11181,7 @@ restart_grand:
#endif
if ((cstat&dasprclipmask) == 0) continue;
#ifdef HAVE_CLIPSHAPE_FEATURE
// try and see whether this sprite's picnum has sector-like clipping data
i = pictoidx[spr->picnum];
// handle sector-like floor sprites separately
@ -11175,7 +11192,7 @@ restart_grand:
clipspritelist[clipspritenum++] = z;
continue;
}
#endif
x1 = spr->x; y1 = spr->y; z1 = spr->z;
switch (cstat&48)
{
@ -11305,8 +11322,10 @@ restart_grand:
}
while (++tempshortcnt < tempshortnum || clipspritecnt < clipspritenum);
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
mapinfo_set(NULL, &origmapinfo);
#endif
#ifdef YAX_ENABLE
if (numyaxbunches == 0 || editstatus)
@ -11650,6 +11669,7 @@ int32_t lastwall(int16_t point)
int32_t clipmoveboxtracenum = 3;
#ifdef HAVE_CLIPSHAPE_FEATURE
static int32_t clipsprite_try(const spritetype *spr, int32_t xmin, int32_t ymin, int32_t xmax, int32_t ymax)
{
int32_t i,k,tempint1,tempint2;
@ -11773,7 +11793,7 @@ static int32_t clipsprite_initindex(int32_t curidx, spritetype *curspr, int32_t
return flipmul;
}
#endif
static int32_t clipmove_warned=0;
@ -11844,6 +11864,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
clipspritecnt = 0; clipspritenum = 0;
do
{
#ifdef HAVE_CLIPSHAPE_FEATURE
if (clipsectcnt>=clipsectnum)
{
// one bunch of sectors completed (either the very first
@ -11878,7 +11899,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
clipsprite_initindex(curidx, curspr, &clipsectcnt, pos);
}
#endif
dasect = clipsectorlist[clipsectcnt++];
//if (curspr)
@ -11904,6 +11925,8 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
if (dax >= day) continue;
clipyou = 0;
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
{
if (wal->nextsector>=0)
@ -11933,7 +11956,9 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
}
}
}
else if ((wal->nextsector < 0) || (wal->cstat&dawalclipmask)) clipyou = 1;
else
#endif
if ((wal->nextsector < 0) || (wal->cstat&dawalclipmask)) clipyou = 1;
else if (editstatus == 0)
{
if (rintersect(pos->x,pos->y,0,gx,gy,0,x1,y1,x2,y2,&dax,&day,&daz) == 0)
@ -11983,9 +12008,10 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
}
}
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
continue; // next sector of this index
#endif
if (!dasprclipmask)
continue;
@ -11995,9 +12021,10 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
cstat = spr->cstat;
if ((cstat&dasprclipmask) == 0) continue;
#ifdef HAVE_CLIPSHAPE_FEATURE
if (clipsprite_try(spr, xmin,ymin, xmax,ymax))
continue;
#endif
x1 = spr->x; y1 = spr->y;
switch (cstat&48)
@ -12118,6 +12145,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
}
while (clipsectcnt < clipsectnum || clipspritecnt < clipspritenum);
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
{
// restore original map
@ -12126,6 +12154,7 @@ int32_t clipmove(vec3_t *pos, int16_t *sectnum,
clipsectnum = origclipsectnum;
Bmemcpy(clipsectorlist, origclipsectorlist, clipsectnum*sizeof(clipsectorlist[0]));
}
#endif
hitwall = 0;
cnt = clipmoveboxtracenum;
@ -12710,6 +12739,7 @@ void getzrange(const vec3_t *pos, int16_t sectnum,
clipsectcnt = 0; clipsectnum = 1;
clipspritecnt = clipspritenum = 0;
#ifdef HAVE_CLIPSHAPE_FEATURE
if (0)
{
beginagain:
@ -12717,12 +12747,14 @@ beginagain:
mapinfo_set(&origmapinfo, &clipmapinfo);
clipsectcnt = clipsectnum; // should be a nop, "safety"...
}
#endif
#ifdef YAX_ENABLE
restart_grand:
#endif
do //Collect sectors inside your square first
{
#ifdef HAVE_CLIPSHAPE_FEATURE
if (clipsectcnt>=clipsectnum)
{
// one set of clip-sprite sectors completed, prepare the next
@ -12770,7 +12802,7 @@ restart_grand:
}
}
}
#endif
sec = &sector[clipsectorlist[clipsectcnt]];
startwall = sec->wallptr; endwall = startwall + sec->wallnum;
for (j=startwall,wal=&wall[startwall]; j<endwall; j++,wal++)
@ -12795,6 +12827,7 @@ restart_grand:
if (wal->cstat&dawalclipmask) continue;
sec = &sector[k];
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
{
if (k==sectq[clipinfo[curidx].qend])
@ -12802,7 +12835,9 @@ restart_grand:
if ((sec->ceilingstat&1) && (sec->floorstat&1))
continue;
}
else if (editstatus == 0)
else
#endif
if (editstatus == 0)
{
if (((sec->ceilingstat&1) == 0) && (pos->z <= sec->ceilingz+(3<<8))) continue;
if (((sec->floorstat&1) == 0) && (pos->z >= sec->floorz-(3<<8))) continue;
@ -12825,6 +12860,8 @@ restart_grand:
#endif
//It actually got here, through all the continue's!!!
getzsofslope(k, pos->x,pos->y, &daz,&daz2);
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
{
int32_t fz,cz, hitwhat=(curspr-sprite)+49152;
@ -12842,6 +12879,7 @@ restart_grand:
}
}
else
#endif
{
#ifdef YAX_ENABLE
int16_t cb, fb;
@ -12865,11 +12903,13 @@ restart_grand:
}
while (clipsectcnt < clipsectnum || clipspritecnt < clipspritenum);
#ifdef HAVE_CLIPSHAPE_FEATURE
if (curspr)
{
mapinfo_set(NULL, &origmapinfo); // restore original map
clipsectnum = clipspritenum = 0; // skip the next for loop and check afterwards
}
#endif
for (i=0; i<clipsectnum; i++)
{
@ -12879,9 +12919,10 @@ restart_grand:
cstat = spr->cstat;
if (cstat&dasprclipmask)
{
#ifdef HAVE_CLIPSHAPE_FEATURE
if (clipsprite_try(spr, xmin,ymin, xmax,ymax))
continue;
#endif
x1 = spr->x; y1 = spr->y;
clipyou = 0;
@ -12986,8 +13027,10 @@ restart_grand:
}
}
#ifdef HAVE_CLIPSHAPE_FEATURE
if (clipspritenum>0)
goto beginagain;
#endif
#ifdef YAX_ENABLE
if (numyaxbunches > 0)

View file

@ -10389,8 +10389,10 @@ CLEAN_DIRECTORY:
Bfree(ptr);
}
#if !defined DEBUG_MAIN_ARRAYS
if ((i = clipmapinfo_load("_clipshape0.map")) > 0)
initprintf("There was an error loading the sprite clipping map (status %d).\n", i);
#endif
OSD_Exec("autoexec.cfg");

View file

@ -1700,14 +1700,20 @@ static const dataspec_t svgm_udnetw[] =
{ DS_END, 0, 0, 0 }
};
#if !defined DEBUG_MAIN_ARRAYS
# define DS_MAINAR DS_DYNAMIC
#else
# define DS_MAINAR 0
#endif
static const dataspec_t svgm_secwsp[] =
{
{ DS_STRING, "blK:swsp", 0, 1 },
{ DS_NOCHK, &numwalls, sizeof(numwalls), 1 },
{ DS_DYNAMIC|DS_CNT(numwalls), &wall, sizeof(walltype), (intptr_t)&numwalls },
{ DS_MAINAR|DS_CNT(numwalls), &wall, sizeof(walltype), (intptr_t)&numwalls },
{ DS_NOCHK, &numsectors, sizeof(numsectors), 1 },
{ DS_DYNAMIC|DS_CNT(numsectors), &sector, sizeof(sectortype), (intptr_t)&numsectors },
{ DS_DYNAMIC, &sprite, sizeof(spritetype), MAXSPRITES },
{ DS_MAINAR|DS_CNT(numsectors), &sector, sizeof(sectortype), (intptr_t)&numsectors },
{ DS_MAINAR, &sprite, sizeof(spritetype), MAXSPRITES },
#ifdef YAX_ENABLE
{ DS_NOCHK, &numyaxbunches, sizeof(numyaxbunches), 1 },
{ DS_CNT(numsectors), yax_bunchnum, sizeof(yax_bunchnum[0]), (intptr_t)&numsectors },
@ -1723,7 +1729,7 @@ static const dataspec_t svgm_secwsp[] =
#ifdef USE_OPENGL
{ DS_SAVEFN, (void *)&sv_prespriteextsave, 0, 1 },
#endif
{ DS_DYNAMIC, &spriteext, sizeof(spriteext_t), MAXSPRITES },
{ DS_MAINAR, &spriteext, sizeof(spriteext_t), MAXSPRITES },
#ifdef USE_OPENGL
{ DS_SAVEFN|DS_LOADFN, (void *)&sv_postspriteext, 0, 1 },
#endif