shithub: choc

Download patch

ref: ce7f7c8f4ff189d21b6d9f9cb6b1c987740414e8
parent: 5329fb5d75971138b20abf940ed63635bd2861e0
author: Fabian Greffrath <fabian@greffrath.com>
date: Fri Jul 20 09:18:56 EDT 2018

make some initialization functions (well, kind of) reentrant

In Choco these functions are run only once at start-up, so this will
make no difference, but for Crispy I want to support changing the
framebuffer size in-game, thus I will need to be able to re-run these
functions at run-time.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1265,6 +1265,12 @@
 
     // Create the 8-bit paletted and the 32-bit RGBA screenbuffer surfaces.
 
+    if (screenbuffer != NULL)
+    {
+        SDL_FreeSurface(screenbuffer);
+        screenbuffer = NULL;
+    }
+
     if (screenbuffer == NULL)
     {
         screenbuffer = SDL_CreateRGBSurface(0,
@@ -1275,6 +1281,13 @@
 
     // Format of argbbuffer must match the screen pixel format because we
     // import the surface data into the texture.
+
+    if (argbbuffer != NULL)
+    {
+        SDL_FreeSurface(argbbuffer);
+        argbbuffer = NULL;
+    }
+
     if (argbbuffer == NULL)
     {
         SDL_PixelFormatEnumToMasks(pixel_format, &unused_bpp,
--- a/src/v_diskicon.c
+++ b/src/v_diskicon.c
@@ -73,6 +73,13 @@
     V_UseBuffer(tmpscreen);
 
     // Buffer where we'll save the disk data.
+
+    if (disk_data != NULL)
+    {
+        Z_Free(disk_data);
+        disk_data = NULL;
+    }
+
     disk_data = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H * sizeof(*disk_data),
                          PU_STATIC, NULL);
 
@@ -92,6 +99,12 @@
 {
     loading_disk_xoffs = xoffs;
     loading_disk_yoffs = yoffs;
+
+    if (saved_background != NULL)
+    {
+        Z_Free(saved_background);
+        saved_background = NULL;
+    }
 
     saved_background = Z_Malloc(LOADING_DISK_W * LOADING_DISK_H
                                  * sizeof(*saved_background),