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 void
VID_Update (vrect_t *rects) VID_Update (vrect_t *rects)
{ {
SDL_Rect *sdlrects; static SDL_Rect *sdlrects;
static int num_sdlrects;
int i, n; int i, n;
vrect_t *rect; vrect_t *rect;
@ -152,9 +153,14 @@ VID_Update (vrect_t *rects)
for (rect = rects; rect; rect = rect->next) for (rect = rects; rect; rect = rect->next)
++n; ++n;
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 // Second, copy them to SDL rectangles and update
if (!(sdlrects = (SDL_Rect *) calloc (1, n * sizeof (SDL_Rect))))
Sys_Error ("Out of memory!");
i = 0; i = 0;
for (rect = rects; rect; rect = rect->next) { for (rect = rects; rect; rect = rect->next) {
sdlrects[i].x = rect->x; sdlrects[i].x = rect->x;
@ -167,7 +173,7 @@ VID_Update (vrect_t *rects)
} }
void void
D_BeginDirectRect (int x, int y, byte * pbitmap, int width, int height) D_BeginDirectRect (int x, int y, byte *pbitmap, int width, int height)
{ {
Uint8 *offset; Uint8 *offset;