commit ce7f7c8f4ff189d21b6d9f9cb6b1c987740414e8
Author: Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Fri Jul 20 13:18:56 2018 +0200
Commit: Fabian Greffrath <fabian@greffrath.com>
CommitDate: Fri Jul 20 13:18:56 2018 +0200
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.
---
src/i_video.c | 13 +++++++++++++
src/v_diskicon.c | 13 +++++++++++++
2 files changed, 26 insertions(+)
diff --git a/src/i_video.c b/src/i_video.c
index 05460255..d81ec882 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -1265,6 +1265,12 @@ static void SetVideoMode(void)
// 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 @@ static void SetVideoMode(void)
// 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,
diff --git a/src/v_diskicon.c b/src/v_diskicon.c
index a39a2b63..e809a7ca 100644
--- a/src/v_diskicon.c
+++ b/src/v_diskicon.c
@@ -73,6 +73,13 @@ static void SaveDiskData(const char *disk_lump, int xoffs, int yoffs)
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);
@@ -93,6 +100,12 @@ void V_EnableLoadingDisk(const char *lump_name, int xoffs, int yoffs)
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),
PU_STATIC, NULL);