From d73fc7912a46d4cb9c3e07f01f5ae2d64e7d9ff5 Mon Sep 17 00:00:00 2001 From: Dudemanguy Date: Sun, 8 Jan 2023 13:31:03 -0600 Subject: [PATCH] wayland: cleanup on vo_wayland_init error Instead of just returning true/false, it's better to have this function cleanup itself. We can eliminate some redundant uninit calls elsewhere in the code as well. --- video/out/opengl/context_wayland.c | 5 +---- video/out/wayland_common.c | 16 ++++++++++------ video/out/wldmabuf/context_wldmabuf.c | 4 +--- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/video/out/opengl/context_wayland.c b/video/out/opengl/context_wayland.c index 2782d46509..ac843f8c43 100644 --- a/video/out/opengl/context_wayland.c +++ b/video/out/opengl/context_wayland.c @@ -208,11 +208,8 @@ static void wayland_egl_update_render_opts(struct ra_ctx *ctx) static bool wayland_egl_init(struct ra_ctx *ctx) { - if (!vo_wayland_init(ctx->vo)) { - vo_wayland_uninit(ctx->vo); + if (!vo_wayland_init(ctx->vo)) return false; - } - return egl_create_context(ctx); } diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index ed7e68c9ad..dadc93a5ef 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -1953,10 +1953,10 @@ bool vo_wayland_init(struct vo *vo) wl_list_init(&wl->output_list); if (!wl->display) - return false; + goto err; if (create_input(wl)) - return false; + goto err; wl->registry = wl_display_get_registry(wl->display); wl_registry_add_listener(wl->registry, ®istry_listener, wl); @@ -1967,24 +1967,24 @@ bool vo_wayland_init(struct vo *vo) if (!wl->surface) { MP_FATAL(wl, "Compositor doesn't support %s (ver. 4)\n", wl_compositor_interface.name); - return false; + goto err; } if (!wl->wm_base) { MP_FATAL(wl, "Compositor doesn't support the required %s protocol!\n", xdg_wm_base_interface.name); - return false; + goto err; } if (!wl_list_length(&wl->output_list)) { MP_FATAL(wl, "No outputs found or compositor doesn't support %s (ver. 2)\n", wl_output_interface.name); - return false; + goto err; } /* Can't be initialized during registry due to multi-protocol dependence */ if (create_xdg_surface(wl)) - return false; + goto err; if (wl->subcompositor) { wl->video_subsurface = wl_subcompositor_get_subsurface(wl->subcompositor, wl->video_surface, wl->surface); @@ -2063,6 +2063,10 @@ bool vo_wayland_init(struct vo *vo) wl_display_roundtrip(wl->display); return true; + +err: + vo_wayland_uninit(vo); + return false; } int vo_wayland_reconfig(struct vo *vo) diff --git a/video/out/wldmabuf/context_wldmabuf.c b/video/out/wldmabuf/context_wldmabuf.c index 0a5999ad73..472374c427 100644 --- a/video/out/wldmabuf/context_wldmabuf.c +++ b/video/out/wldmabuf/context_wldmabuf.c @@ -27,10 +27,8 @@ static void uninit(struct ra_ctx *ctx) static bool init(struct ra_ctx *ctx) { - if (!vo_wayland_init(ctx->vo)) { - vo_wayland_uninit(ctx->vo); + if (!vo_wayland_init(ctx->vo)) return false; - } ctx->ra = ra_create_wayland(ctx->log, ctx->vo->wl->display); return true;