Factorize screen_init() error management

This commit is contained in:
Romain Vimont 2021-05-16 18:36:07 +02:00
parent e604e8a752
commit dcee7c0f7f

View file

@ -307,8 +307,7 @@ screen_init(struct screen *screen, const struct screen_params *params) {
if (!fps_counter_init(&screen->fps_counter)) { if (!fps_counter_init(&screen->fps_counter)) {
LOGE("Could not initialize FPS counter"); LOGE("Could not initialize FPS counter");
video_buffer_destroy(&screen->vb); goto error_destroy_video_buffer;
return false;
} }
screen->frame_size = params->frame_size; screen->frame_size = params->frame_size;
@ -347,19 +346,14 @@ screen_init(struct screen *screen, const struct screen_params *params) {
window_flags); window_flags);
if (!screen->window) { if (!screen->window) {
LOGC("Could not create window: %s", SDL_GetError()); LOGC("Could not create window: %s", SDL_GetError());
fps_counter_destroy(&screen->fps_counter); goto error_destroy_fps_counter;
video_buffer_destroy(&screen->vb);
return false;
} }
screen->renderer = SDL_CreateRenderer(screen->window, -1, screen->renderer = SDL_CreateRenderer(screen->window, -1,
SDL_RENDERER_ACCELERATED); SDL_RENDERER_ACCELERATED);
if (!screen->renderer) { if (!screen->renderer) {
LOGC("Could not create renderer: %s", SDL_GetError()); LOGC("Could not create renderer: %s", SDL_GetError());
SDL_DestroyWindow(screen->window); goto error_destroy_window;
fps_counter_destroy(&screen->fps_counter);
video_buffer_destroy(&screen->vb);
return false;
} }
SDL_RendererInfo renderer_info; SDL_RendererInfo renderer_info;
@ -408,22 +402,13 @@ screen_init(struct screen *screen, const struct screen_params *params) {
screen->texture = create_texture(screen); screen->texture = create_texture(screen);
if (!screen->texture) { if (!screen->texture) {
LOGC("Could not create texture: %s", SDL_GetError()); LOGC("Could not create texture: %s", SDL_GetError());
SDL_DestroyRenderer(screen->renderer); goto error_destroy_renderer;
SDL_DestroyWindow(screen->window);
fps_counter_destroy(&screen->fps_counter);
video_buffer_destroy(&screen->vb);
return false;
} }
screen->frame = av_frame_alloc(); screen->frame = av_frame_alloc();
if (!screen->frame) { if (!screen->frame) {
LOGC("Could not create screen frame"); LOGC("Could not create screen frame");
SDL_DestroyTexture(screen->texture); goto error_destroy_texture;
SDL_DestroyRenderer(screen->renderer);
SDL_DestroyWindow(screen->window);
fps_counter_destroy(&screen->fps_counter);
video_buffer_destroy(&screen->vb);
return false;
} }
// Reset the window size to trigger a SIZE_CHANGED event, to workaround // Reset the window size to trigger a SIZE_CHANGED event, to workaround
@ -454,6 +439,19 @@ screen_init(struct screen *screen, const struct screen_params *params) {
#endif #endif
return true; return true;
error_destroy_texture:
SDL_DestroyTexture(screen->texture);
error_destroy_renderer:
SDL_DestroyRenderer(screen->renderer);
error_destroy_window:
SDL_DestroyWindow(screen->window);
error_destroy_fps_counter:
fps_counter_destroy(&screen->fps_counter);
error_destroy_video_buffer:
video_buffer_destroy(&screen->vb);
return false;
} }
static void static void