Fix lockup bug in Win32 - cleaned up VID_Allocbuffers (copy/paste from *nix counterparts :-)

This commit is contained in:
Dabb 2000-11-07 18:09:20 +00:00
parent f5a77e3441
commit 10d9030dc9

View file

@ -270,44 +270,43 @@ VID_AllocBuffers
qboolean qboolean
VID_AllocBuffers (int width, int height) VID_AllocBuffers (int width, int height)
{ {
int tbuffersize, tcachesize; int zbuffersize, cachesize;
void *temp_z, *temp_sc;
tbuffersize = width * height * sizeof (*d_pzbuffer); // Calculate the sizes we want first
tcachesize = D_SurfaceCacheForRes (width, height);
// Allocate the new z-buffer zbuffersize = width * height * sizeof (*d_pzbuffer);
temp_z = calloc (tbuffersize, 1); cachesize = D_SurfaceCacheForRes(width, height);
if (temp_z == NULL) {
Sys_Printf ("Not enough memory for video mode\n");
return false;
}
// Allocate the new surface cache // Free the old z-buffer
temp_sc = calloc (tcachesize, 1);
if (temp_sc == NULL) {
free (temp_z);
Sys_Printf ("Not enough memory for video mode\n");
return false;
}
// Free the old z-buffer, switch to the new one
if (d_pzbuffer) { if (d_pzbuffer) {
free (d_pzbuffer); free (d_pzbuffer);
d_pzbuffer = temp_z; d_pzbuffer = NULL;
temp_z = NULL;
} }
vid_surfcachesize = tcachesize; // Free the old surface cache
// Free surface cache, switch to the new one
vid_surfcache = D_SurfaceCacheAddress (); vid_surfcache = D_SurfaceCacheAddress ();
if (vid_surfcache) { if (vid_surfcache) {
D_FlushCaches (); D_FlushCaches ();
free (vid_surfcache); free (vid_surfcache);
vid_surfcache = NULL;
} }
vid_surfcache = temp_sc;
temp_sc = NULL; // Allocate the new z-buffer
d_pzbuffer = calloc (zbuffersize, 1);
if (!d_pzbuffer) {
free (vid.buffer);
Sys_Error ("Not enough memory for video mode\n");
}
// Allocate the new surface cache; free the z-buffer if we fail
vid_surfcache = calloc (cachesize, 1);
if (!vid_surfcache) {
free (d_pzbuffer);
d_pzbuffer = NULL;
Sys_Error ("Not enough memory for video mode\n");
}
vid_surfcachesize = cachesize;
return true; return true;
} }
@ -1723,7 +1722,7 @@ int VID_SetMode (int modenum, unsigned char *palette)
return false; return false;
} }
D_InitCaches (vid_surfcache, vid_surfcachesize); D_InitCaches (vid_surfcache, vid_surfcachesize);
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{ {