From 9a831cb20654c4322f9cae9b005165313d2a47b6 Mon Sep 17 00:00:00 2001 From: adityaraj <75035219+pegvin@users.noreply.github.com> Date: Thu, 12 Jan 2023 05:23:23 +0530 Subject: [PATCH] Create Renderer Only When It Doesn't Exist (#1315) --- src/renwindow.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/renwindow.c b/src/renwindow.c index c381e772..468bcaf9 100644 --- a/src/renwindow.c +++ b/src/renwindow.c @@ -10,7 +10,7 @@ static int query_surface_scale(RenWindow *ren) { SDL_GetWindowSize(ren->window, &w_points, &h_points); /* We consider that the ratio pixel/point will always be an integer and it is the same along the x and the y axis. */ - + #if defined(__amigaos4__) || defined(__morphos__) // This is a workaround when the w_pixels != w_points and h_pixels != h_points // because of redraw delays, especially when the "Resize with contents" is enabled @@ -21,7 +21,7 @@ static int query_surface_scale(RenWindow *ren) { h_pixels = h_points; } #endif - + assert(w_pixels % w_points == 0 && h_pixels % h_points == 0 && w_pixels / w_points == h_pixels / h_points); return w_pixels / w_points; } @@ -29,11 +29,12 @@ static int query_surface_scale(RenWindow *ren) { static void setup_renderer(RenWindow *ren, int w, int h) { /* Note that w and h here should always be in pixels and obtained from a call to SDL_GL_GetDrawableSize(). */ - if (ren->renderer) { - SDL_DestroyTexture(ren->texture); - SDL_DestroyRenderer(ren->renderer); + if (!ren->renderer) { + ren->renderer = SDL_CreateRenderer(ren->window, -1, 0); + } + if (ren->texture) { + SDL_DestroyTexture(ren->texture); } - ren->renderer = SDL_CreateRenderer(ren->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); ren->texture = SDL_CreateTexture(ren->renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, w, h); ren->surface_scale = query_surface_scale(ren); }