Restore allocate buffers on render init

This commit is contained in:
Denis Pauk 2018-07-24 16:56:42 +03:00
parent a37d6cb07a
commit 25cb7acda8
3 changed files with 107 additions and 40 deletions

View file

@ -173,7 +173,7 @@ CFLAGS := -O2 -fno-strict-aliasing -fomit-frame-pointer \
-Wall -pipe -g -fwrapv -Wall -pipe -g -fwrapv
CFLAGS += $(OSX_ARCH) CFLAGS += $(OSX_ARCH)
else else
CFLAGS := -std=gnu99 -O2 -fno-strict-aliasing \ CFLAGS := -std=gnu99 -fno-strict-aliasing \
-Wall -pipe -g -ggdb -MMD -fwrapv -Wall -pipe -g -ggdb -MMD -fwrapv
endif endif

View file

@ -569,6 +569,7 @@ extern void *colormap;
//==================================================================== //====================================================================
void R_NewMap (void); void R_NewMap (void);
void R_ReallocateMapBuffers (void);
void Draw_InitLocal(void); void Draw_InitLocal(void);
void R_InitCaches(void); void R_InitCaches(void);
void D_FlushCaches(void); void D_FlushCaches(void);

View file

@ -401,31 +401,64 @@ R_NewMap
void R_NewMap (void) void R_NewMap (void)
{ {
r_viewcluster = -1; r_viewcluster = -1;
}
r_cnumsurfs = sw_maxsurfs->value; surf_t *lsurfs;
if (r_cnumsurfs <= NUMSTACKSURFACES) /*
===============
R_ReallocateMapBuffers
===============
*/
void
R_ReallocateMapBuffers (void)
{
if (!r_cnumsurfs)
{
if(lsurfs)
{
free(lsurfs);
}
if (r_cnumsurfs < NUMSTACKSURFACES)
r_cnumsurfs = NUMSTACKSURFACES; r_cnumsurfs = NUMSTACKSURFACES;
surfaces = malloc (r_cnumsurfs * sizeof(surf_t)); if (r_cnumsurfs < sw_maxsurfs->value)
if (!surfaces) r_cnumsurfs = sw_maxsurfs->value;
lsurfs = malloc (r_cnumsurfs * sizeof(surf_t));
if (!lsurfs)
{ {
R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n", R_Printf(PRINT_ALL, "%s: Couldn't malloc %d bytes\n",
__func__, (int)(r_cnumsurfs * sizeof(surf_t))); __func__, (int)(r_cnumsurfs * sizeof(surf_t)));
return; return;
} }
surface_p = surfaces; surface_p = surfaces = lsurfs;
surf_max = &surfaces[r_cnumsurfs]; surf_max = &surfaces[r_cnumsurfs];
// surface 0 doesn't really exist; it's just a dummy because index 0 // surface 0 doesn't really exist; it's just a dummy because index 0
// is used to indicate no edge attached to surface // is used to indicate no edge attached to surface
surfaces--; surfaces--;
r_numallocatededges = sw_maxedges->value; R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n",
__func__, r_cnumsurfs);
}
if (!r_numallocatededges)
{
if (!r_edges)
{
free(r_edges);
}
if (r_numallocatededges < NUMSTACKEDGES) if (r_numallocatededges < NUMSTACKEDGES)
r_numallocatededges = NUMSTACKEDGES; r_numallocatededges = NUMSTACKEDGES;
if (r_numallocatededges < sw_maxedges->value)
r_numallocatededges = sw_maxedges->value;
r_edges = malloc (r_numallocatededges * sizeof(edge_t)); r_edges = malloc (r_numallocatededges * sizeof(edge_t));
if (!r_edges) if (!r_edges)
{ {
@ -434,7 +467,20 @@ void R_NewMap (void)
return; return;
} }
R_Printf(PRINT_ALL, "%s: Allocated %d edges\n",
__func__, r_numallocatededges);
}
if (!r_numallocatedverts)
{
if (finalverts)
{
free(finalverts);
}
if (r_numallocatedverts < MAXALIASVERTS)
r_numallocatedverts = MAXALIASVERTS; r_numallocatedverts = MAXALIASVERTS;
finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t)); finalverts = malloc(r_numallocatedverts * sizeof(finalvert_t));
if (!finalverts) if (!finalverts)
{ {
@ -444,13 +490,10 @@ void R_NewMap (void)
} }
finalverts_max = &finalverts[r_numallocatedverts]; finalverts_max = &finalverts[r_numallocatedverts];
R_Printf(PRINT_ALL, "%s: Allocated %d edges\n",
__func__, r_numallocatededges);
R_Printf(PRINT_ALL, "%s: Allocated %d surfaces\n",
__func__, r_cnumsurfs);
R_Printf(PRINT_ALL, "%s: Allocated %d verts\n", R_Printf(PRINT_ALL, "%s: Allocated %d verts\n",
__func__, r_numallocatedverts); __func__, r_numallocatedverts);
} }
}
/* /*
@ -1756,6 +1799,18 @@ static void SWimp_DestroyRender(void)
} }
finalverts = NULL; finalverts = NULL;
if(r_edges)
{
free(r_edges);
}
r_edges = NULL;
if(lsurfs)
{
free(lsurfs);
}
lsurfs = NULL;
if(r_warpbuffer) if(r_warpbuffer)
{ {
free(r_warpbuffer); free(r_warpbuffer);
@ -1911,6 +1966,17 @@ SWimp_InitGraphics(int fullscreen, int *pwidth, int *pheight)
edge_basespans = malloc((vid.width*2) * sizeof(espan_t)); edge_basespans = malloc((vid.width*2) * sizeof(espan_t));
// count of "out of items"
r_outofsurfaces = r_outofedges = r_outofverts = 0;
// pointers to allocated buffers
finalverts = NULL;
r_edges = NULL;
lsurfs = NULL;
// curently allocated items
r_cnumsurfs = r_numallocatededges = r_numallocatedverts = 0;
R_ReallocateMapBuffers();
r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t)); r_warpbuffer = malloc(vid.height * vid.width * sizeof(pixel_t));
if ((vid.width >= 2048) && (sizeof(shift20_t) == 4)) // 2k+ resolution and 32 == shift20_t if ((vid.width >= 2048) && (sizeof(shift20_t) == 4)) // 2k+ resolution and 32 == shift20_t