shithub: choc

Download patch

ref: 07e9f3b987cc45c6e5ddd8197309f977d914f6a6
parent: e9b9fefcf6b8163de9062430118fd626e79fa2c2
author: Fabian Greffrath <fabian@greffrath.com>
date: Thu Dec 20 06:05:41 EST 2018

video: create new texture before destroying old one

This fixes a racing condition which would leave us with no
intermediate texture available until the new one is created.

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -608,6 +608,8 @@
     int h_upscale, w_upscale;
     static int h_upscale_old, w_upscale_old;
 
+    SDL_Texture *new_texture, *old_texture;
+
     // Get the size of the renderer output. The units this gives us will be
     // real world pixels, which are not necessarily equivalent to the screen's
     // window size (because of highdpi).
@@ -663,11 +665,6 @@
     h_upscale_old = h_upscale;
     w_upscale_old = w_upscale;
 
-    if (texture_upscaled)
-    {
-        SDL_DestroyTexture(texture_upscaled);
-    }
-
     // Set the scaling quality for rendering the upscaled texture to "linear",
     // which looks much softer and smoother than "nearest" but does a better
     // job at downscaling from the upscaled texture to screen.
@@ -674,11 +671,19 @@
 
     SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
 
-    texture_upscaled = SDL_CreateTexture(renderer,
+    new_texture = SDL_CreateTexture(renderer,
                                 pixel_format,
                                 SDL_TEXTUREACCESS_TARGET,
                                 w_upscale*SCREENWIDTH,
                                 h_upscale*SCREENHEIGHT);
+
+    old_texture = texture_upscaled;
+    texture_upscaled = new_texture;
+
+    if (old_texture != NULL)
+    {
+        SDL_DestroyTexture(old_texture);
+    }
 }
 
 //