shithub: choc

Download patch

ref: 57a9f56e2cba50249ee8a96533c8baed47814f92
parent: e225e0c93ce58bb0e33c174847305d39800fd755
author: Simon Howard <[email protected]>
date: Fri Dec 10 18:56:32 EST 2010

Fix memory leak when dynamically resizing window in true color video
modes.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2215

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -97,7 +97,7 @@
 // This is used when we are rendering in 32-bit screen mode.
 // When in a real 8-bit screen mode, screenbuffer == screen.
 
-static SDL_Surface *screenbuffer;
+static SDL_Surface *screenbuffer = NULL;
 
 // palette
 
@@ -1645,6 +1645,14 @@
     int flags = 0;
 
     doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE);
+
+    // If we are already running and in a true color mode, we need
+    // to free the screenbuffer surface before setting the new mode.
+
+    if (screenbuffer != NULL && screen != screenbuffer)
+    {
+        SDL_FreeSurface(screenbuffer);
+    }
 
     // Generate lookup tables before setting the video mode.