From 34303e1b47defc7aca518983ac3aaea6c881d112 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Sun, 22 Mar 2020 00:55:54 +1300 Subject: [PATCH] wlr_surface: Post error if multiple role objects created This fixes an assertion failure if a client tries to do this, e.g. by creating multiple toplevel objects for the same surface. If the same role data is set multiple times, this does not cause an error, which is how cursors use this interface. --- types/wlr_surface.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 244a2cad..0b2e8c09 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -667,8 +667,14 @@ bool wlr_surface_set_role(struct wlr_surface *surface, } return false; } + if (surface->role_data != NULL && surface->role_data != role_data) { + wl_resource_post_error(error_resource, error_code, + "Cannot reassign role %s to wl_surface@%d," + "role object still exists", role->name, + wl_resource_get_id(surface->resource)); + return false; + } - assert(surface->role_data == NULL); surface->role = role; surface->role_data = role_data; return true;