From 508d8c9a01568467b15d7cb2cdf906f2d86576a0 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 14 Mar 2024 12:32:04 +0100 Subject: [PATCH] compositor: handle renderer destroy Don't leave a stale renderer pointer behind. --- include/wlr/types/wlr_compositor.h | 1 + types/wlr_compositor.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/wlr/types/wlr_compositor.h b/include/wlr/types/wlr_compositor.h index dc95b303..78de8388 100644 --- a/include/wlr/types/wlr_compositor.h +++ b/include/wlr/types/wlr_compositor.h @@ -247,6 +247,7 @@ struct wlr_compositor { struct wlr_renderer *renderer; // may be NULL struct wl_listener display_destroy; + struct wl_listener renderer_destroy; struct { struct wl_signal new_surface; diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index 791eb77c..915b95e6 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -1348,10 +1348,20 @@ static void compositor_handle_display_destroy( wl_container_of(listener, compositor, display_destroy); wl_signal_emit_mutable(&compositor->events.destroy, NULL); wl_list_remove(&compositor->display_destroy.link); + wl_list_remove(&compositor->renderer_destroy.link); wl_global_destroy(compositor->global); free(compositor); } +static void compositor_handle_renderer_destroy( + struct wl_listener *listener, void *data) { + struct wlr_compositor *compositor = + wl_container_of(listener, compositor, renderer_destroy); + compositor->renderer = NULL; + wl_list_remove(&compositor->renderer_destroy.link); + wl_list_init(&compositor->renderer_destroy.link); +} + struct wlr_compositor *wlr_compositor_create(struct wl_display *display, uint32_t version, struct wlr_renderer *renderer) { assert(version <= COMPOSITOR_VERSION); @@ -1375,6 +1385,13 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display, compositor->display_destroy.notify = compositor_handle_display_destroy; wl_display_add_destroy_listener(display, &compositor->display_destroy); + if (renderer != NULL) { + compositor->renderer_destroy.notify = compositor_handle_renderer_destroy; + wl_signal_add(&renderer->events.destroy, &compositor->renderer_destroy); + } else { + wl_list_init(&compositor->renderer_destroy.link); + } + return compositor; }