From 0538e9645b3aebddbe9d579cbc5c4ca8f64c3659 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sat, 13 Feb 2021 14:40:00 +0100 Subject: [PATCH] Improve error handling in screen initialization After the struct screen is initialized, the window, the renderer and the texture are necessarily valid, so there is no need to check in screen_destroy(). --- app/src/screen.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/app/src/screen.c b/app/src/screen.c index 1136d547..959af9c7 100644 --- a/app/src/screen.c +++ b/app/src/screen.c @@ -270,7 +270,7 @@ screen_init_rendering(struct screen *screen, const char *window_title, SDL_RENDERER_ACCELERATED); if (!screen->renderer) { LOGC("Could not create renderer: %s", SDL_GetError()); - screen_destroy(screen); + SDL_DestroyWindow(screen->window); return false; } @@ -318,7 +318,8 @@ screen_init_rendering(struct screen *screen, const char *window_title, screen->texture = create_texture(screen); if (!screen->texture) { LOGC("Could not create texture: %s", SDL_GetError()); - screen_destroy(screen); + SDL_DestroyRenderer(screen->renderer); + SDL_DestroyWindow(screen->window); return false; } @@ -339,15 +340,9 @@ screen_show_window(struct screen *screen) { void screen_destroy(struct screen *screen) { - if (screen->texture) { - SDL_DestroyTexture(screen->texture); - } - if (screen->renderer) { - SDL_DestroyRenderer(screen->renderer); - } - if (screen->window) { - SDL_DestroyWindow(screen->window); - } + SDL_DestroyTexture(screen->texture); + SDL_DestroyRenderer(screen->renderer); + SDL_DestroyWindow(screen->window); } static void