diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index de3aeec3d..9a655dd2b 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -151,6 +151,7 @@ struct wlr_client_buffer { // private state struct wl_listener source_destroy; + struct wl_listener renderer_destroy; size_t n_ignore_locks; }; diff --git a/types/buffer/client.c b/types/buffer/client.c index 4cfa57a89..d96603a45 100644 --- a/types/buffer/client.c +++ b/types/buffer/client.c @@ -25,6 +25,7 @@ static struct wlr_client_buffer *client_buffer_from_buffer( static void client_buffer_destroy(struct wlr_buffer *buffer) { struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer); wl_list_remove(&client_buffer->source_destroy.link); + wl_list_remove(&client_buffer->renderer_destroy.link); wlr_texture_destroy(client_buffer->texture); free(client_buffer); } @@ -54,6 +55,15 @@ static void client_buffer_handle_source_destroy(struct wl_listener *listener, client_buffer->source = NULL; } +static void client_buffer_handle_renderer_destroy(struct wl_listener *listener, + void *data) { + struct wlr_client_buffer *client_buffer = + wl_container_of(listener, client_buffer, renderer_destroy); + wl_list_remove(&client_buffer->renderer_destroy.link); + wl_list_init(&client_buffer->renderer_destroy.link); + client_buffer->texture = NULL; +} + struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, struct wlr_renderer *renderer) { struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer); @@ -75,6 +85,9 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, wl_signal_add(&buffer->events.destroy, &client_buffer->source_destroy); client_buffer->source_destroy.notify = client_buffer_handle_source_destroy; + wl_signal_add(&texture->renderer->events.destroy, &client_buffer->renderer_destroy); + client_buffer->renderer_destroy.notify = client_buffer_handle_renderer_destroy; + // Ensure the buffer will be released before being destroyed wlr_buffer_lock(&client_buffer->base); wlr_buffer_drop(&client_buffer->base); @@ -88,6 +101,9 @@ bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, // Someone else still has a reference to the buffer return false; } + if (client_buffer->texture == NULL) { + return false; + } return wlr_texture_update_from_buffer(client_buffer->texture, next, damage); }