compositor: handle renderer destroy

Don't leave a stale renderer pointer behind.
This commit is contained in:
Simon Ser 2024-03-14 12:32:04 +01:00 committed by Isaac Freund
parent ac1232e576
commit 508d8c9a01
2 changed files with 18 additions and 0 deletions

View file

@ -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;

View file

@ -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;
}