From ae218bc0056418c5333083af5a24e6bafc6f9742 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 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renwindow.c b/src/renwindow.c index 9356ed21..85fd7a07 100644 --- a/src/renwindow.c +++ b/src/renwindow.c @@ -17,11 +17,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, 0); ren->texture = SDL_CreateTexture(ren->renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, w, h); ren->surface_scale = query_surface_scale(ren); }