From 691415bf95b564189f0603f0eeab6bb3e8447bd6 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 10 Feb 2021 17:41:50 +0100 Subject: [PATCH] pool-buffer: handle zero-sized buffers mako does something similar. --- pool-buffer.c | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pool-buffer.c b/pool-buffer.c index aada4c0..7672283 100644 --- a/pool-buffer.c +++ b/pool-buffer.c @@ -72,18 +72,22 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm, uint32_t stride = width * 4; size_t size = stride * height; - char *name; - int fd = create_pool_file(size, &name); - assert(fd != -1); - void *data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size); - buf->buffer = wl_shm_pool_create_buffer(pool, 0, - width, height, stride, format); - wl_shm_pool_destroy(pool); - close(fd); - unlink(name); - free(name); - fd = -1; + void *data = NULL; + if (size > 0) { + char *name; + int fd = create_pool_file(size, &name); + assert(fd != -1); + data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, size); + buf->buffer = wl_shm_pool_create_buffer(pool, 0, + width, height, stride, format); + wl_buffer_add_listener(buf->buffer, &buffer_listener, buf); + wl_shm_pool_destroy(pool); + close(fd); + unlink(name); + free(name); + fd = -1; + } buf->size = size; buf->width = width; @@ -92,8 +96,6 @@ static struct pool_buffer *create_buffer(struct wl_shm *shm, buf->surface = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, width, height, stride); buf->cairo = cairo_create(buf->surface); - - wl_buffer_add_listener(buf->buffer, &buffer_listener, buf); return buf; }