From ba333ebe14da7e15337b6bccffe94cd2a728cbcc Mon Sep 17 00:00:00 2001 From: lsj119 Date: Tue, 30 Apr 2019 11:28:40 +0900 Subject: [PATCH] headless-server::shell : Fix crash Change-Id: I5749f41627be27e6b449e60d78d177b27dcaabbc --- src/bin/headless/shell/shell.c | 24 +++++++++++++++++------- src/samples/headless_client.c | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/bin/headless/shell/shell.c b/src/bin/headless/shell/shell.c index 5c28b0e..b6284b6 100644 --- a/src/bin/headless/shell/shell.c +++ b/src/bin/headless/shell/shell.c @@ -465,6 +465,7 @@ zxdg_shell_cb_surface_get(struct wl_client *client, struct wl_resource *resource headless_shell_t *hs; headless_shell_surface_t *hs_surface = NULL; pepper_surface_t *psurface; + const char *role; hs = wl_resource_get_user_data(resource); if (!hs) { @@ -513,11 +514,16 @@ zxdg_shell_cb_surface_get(struct wl_client *client, struct wl_resource *resource hs_surface->cb_commit = pepper_object_add_event_listener((pepper_object_t *)psurface, PEPPER_EVENT_SURFACE_COMMIT, 0, headless_shell_cb_surface_commit, hs_surface); - if (!pepper_surface_set_role(psurface, "xdg_surface")) { - PEPPER_ERROR("fail to set role\n"); - wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, - "Assign \"xdg_surface\" to wl_surface failed\n"); - goto error; + role = pepper_surface_get_role(psurface); + if (!role) { + if (!pepper_surface_set_role(psurface, "xdg_surface")) { + PEPPER_ERROR("fail to set role\n"); + wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_OBJECT, + "Assign \"xdg_surface\" to wl_surface failed\n"); + goto error; + } + } else { + PEPPER_CHECK(!strcmp(role, "xdg_surface"), goto error, "surface has alweady role %s\n", role); } PEPPER_TRACE("[SHELL] create zxdg_surface:%p, pview:%p, psurface:%p\n", @@ -528,11 +534,15 @@ zxdg_shell_cb_surface_get(struct wl_client *client, struct wl_resource *resource return; error: if (hs_surface) { - if (hs_surface->view) + if (hs_surface->view) { pepper_view_destroy(hs_surface->view); + hs_surface->view = NULL; + } - if (hs_surface->zxdg_shell_surface) + if (hs_surface->zxdg_shell_surface) { wl_resource_destroy(hs_surface->zxdg_shell_surface); + hs_surface->zxdg_shell_surface = NULL; + } } } diff --git a/src/samples/headless_client.c b/src/samples/headless_client.c index a6fb818..dae0286 100644 --- a/src/samples/headless_client.c +++ b/src/samples/headless_client.c @@ -442,6 +442,7 @@ _stdin_cb(void *data, Ecore_Fd_Handler *handler EINA_UNUSED) } else if (!strncmp(tmp, "hide", sizeof("hide"))) { ecore_wl2_window_hide(client->win); + ecore_wl2_window_commit(client->win, EINA_TRUE); printf("hide window\n"); } else if (!strncmp(tmp, "show", sizeof("show"))) { -- 2.34.1