diff --git a/src/r_plane.c b/src/r_plane.c index 4dfab96c..1f550aa9 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -71,8 +71,8 @@ visplane_t *floorplane, *ceilingplane; // killough 8/1/98: set static number of openings to be large enough // (a static limit is okay in this case and avoids difficulties in r_segs.c) -static int *openings = NULL; -int *lastopening; // [FG] 32-bit integer math +int maxopenings; +int *openings, *lastopening; // [FG] 32-bit integer math // Clip values are the solid pixel bounding the range. // floorclip starts out SCREENHEIGHT @@ -128,7 +128,8 @@ void R_InitPlanesRes(void) yslope = Z_Calloc(1, video.height * sizeof(*yslope), PU_RENDERER, NULL); distscale = Z_Calloc(1, video.width * sizeof(*distscale), PU_RENDERER, NULL); - openings = Z_Calloc(1, video.width * video.height * sizeof(*openings), PU_RENDERER, NULL); + maxopenings = video.width * video.height; + openings = Z_Calloc(1, maxopenings * sizeof(*openings), PU_RENDERER, NULL); xtoskyangle = linearsky ? linearskyangle : xtoviewangle; } diff --git a/src/r_plane.h b/src/r_plane.h index 0fb483df..d9b2ab7d 100644 --- a/src/r_plane.h +++ b/src/r_plane.h @@ -28,7 +28,8 @@ struct visplane_s; #define PL_SKYFLAT (0x80000000) // Visplane related. -extern int *lastopening; // [FG] 32-bit integer math +extern int maxopenings; +extern int *openings, *lastopening; // [FG] 32-bit integer math extern int *floorclip, *ceilingclip; // [FG] 32-bit integer math extern fixed_t *yslope, *distscale; diff --git a/src/r_segs.c b/src/r_segs.c index 42a2481f..cbd031e2 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -566,6 +566,13 @@ void R_StoreWallRange(const int start, const int stop) ds_p->curline = curline; rw_stopx = stop+1; + ptrdiff_t pos = lastopening - openings; + size_t need = (rw_stopx - start) * sizeof(*lastopening) + pos; + if (need > maxopenings) + { + return; + } + // WiggleFix: add this line, in r_segs.c:R_StoreWallRange, // right before calls to R_ScaleFromGlobalAngle R_FixWiggle(frontsector);