compositor: handle renderer destroy

Don't leave a stale renderer pointer behind.
master
Simon Ser 8 months ago committed by Isaac Freund
parent ac1232e576
commit 508d8c9a01

@ -247,6 +247,7 @@ struct wlr_compositor {
struct wlr_renderer *renderer; // may be NULL struct wlr_renderer *renderer; // may be NULL
struct wl_listener display_destroy; struct wl_listener display_destroy;
struct wl_listener renderer_destroy;
struct { struct {
struct wl_signal new_surface; struct wl_signal new_surface;

@ -1348,10 +1348,20 @@ static void compositor_handle_display_destroy(
wl_container_of(listener, compositor, display_destroy); wl_container_of(listener, compositor, display_destroy);
wl_signal_emit_mutable(&compositor->events.destroy, NULL); wl_signal_emit_mutable(&compositor->events.destroy, NULL);
wl_list_remove(&compositor->display_destroy.link); wl_list_remove(&compositor->display_destroy.link);
wl_list_remove(&compositor->renderer_destroy.link);
wl_global_destroy(compositor->global); wl_global_destroy(compositor->global);
free(compositor); 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, struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
uint32_t version, struct wlr_renderer *renderer) { uint32_t version, struct wlr_renderer *renderer) {
assert(version <= COMPOSITOR_VERSION); 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; compositor->display_destroy.notify = compositor_handle_display_destroy;
wl_display_add_destroy_listener(display, &compositor->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; return compositor;
} }

Loading…
Cancel
Save