From 5885679e33b4082e727fb55e1700b67159ec9d06 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 19 Aug 2017 09:26:25 +0200 Subject: [PATCH] examples: separate compositor_fini from run compositor_fini destroys the display, but it is an error to destroy it before e.g. wlr_seat that references it. This lets us order destroy calls properly, following first-in-last-out logic. --- examples/compositor/main.c | 10 +++++++--- examples/output-layout.c | 3 ++- examples/pointer.c | 3 ++- examples/rotation.c | 3 ++- examples/shared.c | 3 +-- examples/shared.h | 2 +- examples/simple.c | 3 ++- examples/tablet.c | 3 ++- examples/touch.c | 3 ++- 9 files changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/compositor/main.c b/examples/compositor/main.c index fdc4ed67e..4c6e213d4 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -178,9 +178,13 @@ int main() { break; } - compositor_run(&compositor); + wl_display_run(compositor.display); - wlr_wl_shell_destroy(state.wl_shell); - wlr_xdg_shell_v6_destroy(state.xdg_shell); close(state.keymap_fd); + wlr_seat_destroy(state.wl_seat); + wlr_data_device_manager_destroy(state.data_device_manager); + wlr_xdg_shell_v6_destroy(state.xdg_shell); + wlr_wl_shell_destroy(state.wl_shell); + wlr_renderer_destroy(state.renderer); + compositor_fini(&compositor); } diff --git a/examples/output-layout.c b/examples/output-layout.c index 565b21a63..0dcbc1f84 100644 --- a/examples/output-layout.c +++ b/examples/output-layout.c @@ -198,10 +198,11 @@ int main(int argc, char *argv[]) { wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888, cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); - compositor_run(&compositor); + wl_display_run(compositor.display); wlr_texture_destroy(state.cat_texture); wlr_renderer_destroy(state.renderer); + compositor_fini(&compositor); wlr_output_layout_destroy(state.layout); diff --git a/examples/pointer.c b/examples/pointer.c index 1325a579a..12253b62b 100644 --- a/examples/pointer.c +++ b/examples/pointer.c @@ -146,7 +146,8 @@ int main(int argc, char *argv[]) { } compositor_init(&compositor); - compositor_run(&compositor); + wl_display_run(compositor.display); + compositor_fini(&compositor); wlr_xcursor_theme_destroy(theme); } diff --git a/examples/rotation.c b/examples/rotation.c index 28f823826..1dcbc80f7 100644 --- a/examples/rotation.c +++ b/examples/rotation.c @@ -145,10 +145,11 @@ int main(int argc, char *argv[]) { wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ABGR8888, cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); - compositor_run(&compositor); + wl_display_run(compositor.display); wlr_texture_destroy(state.cat_texture); wlr_renderer_destroy(state.renderer); + compositor_fini(&compositor); example_config_destroy(state.config); } diff --git a/examples/shared.c b/examples/shared.c index 255652c79..f37140cf9 100644 --- a/examples/shared.c +++ b/examples/shared.c @@ -674,8 +674,7 @@ void compositor_init(struct compositor_state *state) { } } -void compositor_run(struct compositor_state *state) { - wl_display_run(state->display); +void compositor_fini(struct compositor_state *state) { wlr_backend_destroy(state->backend); wl_display_destroy(state->display); } diff --git a/examples/shared.h b/examples/shared.h index 23b2d83d2..d80077531 100644 --- a/examples/shared.h +++ b/examples/shared.h @@ -151,6 +151,6 @@ struct compositor_state { }; void compositor_init(struct compositor_state *state); -void compositor_run(struct compositor_state *state); +void compositor_fini(struct compositor_state *state); #endif diff --git a/examples/simple.c b/examples/simple.c index 8e098e181..7c3cc4963 100644 --- a/examples/simple.c +++ b/examples/simple.c @@ -52,5 +52,6 @@ int main() { .output_frame_cb = handle_output_frame, }; compositor_init(&compositor); - compositor_run(&compositor); + wl_display_run(compositor.display); + compositor_fini(&compositor); } diff --git a/examples/tablet.c b/examples/tablet.c index f43fbc524..4aec5a722 100644 --- a/examples/tablet.c +++ b/examples/tablet.c @@ -158,7 +158,8 @@ int main(int argc, char *argv[]) { wlr_log(L_ERROR, "Could not start compositor, OOM"); exit(EXIT_FAILURE); } - compositor_run(&compositor); + wl_display_run(compositor.display); wlr_renderer_destroy(state.renderer); + compositor_fini(&compositor); } diff --git a/examples/touch.c b/examples/touch.c index 8df95e5b4..7e8d9827a 100644 --- a/examples/touch.c +++ b/examples/touch.c @@ -120,8 +120,9 @@ int main(int argc, char *argv[]) { wlr_texture_upload_pixels(state.cat_texture, WL_SHM_FORMAT_ARGB8888, cat_tex.width, cat_tex.width, cat_tex.height, cat_tex.pixel_data); - compositor_run(&compositor); + wl_display_run(compositor.display); wlr_texture_destroy(state.cat_texture); wlr_renderer_destroy(state.renderer); + compositor_fini(&compositor); }