commit 07e9f3b987cc45c6e5ddd8197309f977d914f6a6
Author: Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Thu Dec 20 11:05:41 2018 +0100
Commit: Fabian Greffrath <fabian@greffrath.com>
CommitDate: Thu Dec 20 11:05:41 2018 +0100
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.
---
src/i_video.c | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/i_video.c b/src/i_video.c
index 80b1e7b7..bcf8c21b 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -608,6 +608,8 @@ static void CreateUpscaledTexture(boolean force)
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,22 +665,25 @@ static void CreateUpscaledTexture(boolean force)
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.
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);
+ }
}
//