Plug a memory leak.

Allocating (and not freeing) rects every frame... ouch.
This commit is contained in:
Bill Currie 2012-02-15 21:49:13 +09:00
parent 96b80433d8
commit 80f5cc59e9

View file

@ -141,7 +141,8 @@ VID_Init (byte *palette, byte *colormap)
void
VID_Update (vrect_t *rects)
{
SDL_Rect *sdlrects;
static SDL_Rect *sdlrects;
static int num_sdlrects;
int i, n;
vrect_t *rect;
@ -152,9 +153,14 @@ VID_Update (vrect_t *rects)
for (rect = rects; rect; rect = rect->next)
++n;
// Second, copy them to SDL rectangles and update
if (!(sdlrects = (SDL_Rect *) calloc (1, n * sizeof (SDL_Rect))))
if (n > num_sdlrects) {
num_sdlrects = n;
sdlrects = realloc (sdlrects, n * sizeof (SDL_Rect));
if (!sdlrects)
Sys_Error ("Out of memory!");
}
// Second, copy them to SDL rectangles and update
i = 0;
for (rect = rects; rect; rect = rect->next) {
sdlrects[i].x = rect->x;