From 4d3251a93b4ba309d573aca6ff397df44c4ff760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 2 Nov 2019 00:48:07 +0100 Subject: [PATCH] render: last_buf may point to a free:d buffer So, store last buf's width/height separately --- render.c | 26 ++++++++++++++++++-------- terminal.h | 6 +++++- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/render.c b/render.c index 0b0c6d5b..d1917eef 100644 --- a/render.c +++ b/render.c @@ -451,25 +451,33 @@ grid_render(struct terminal *term) bool all_clean = tll_length(term->grid->scroll_damage) == 0; /* If we resized the window, or is flashing, or just stopped flashing */ - if (term->render.last_buf != buf || + if (term->render.last_shm.buf != buf || term->flash.active || term->render.was_flashing || term->is_searching != term->render.was_searching) { - if (term->render.last_buf != NULL && - term->render.last_buf->width == buf->width && - term->render.last_buf->height == buf->height && + /* + * TODO: shm buffers may be purged, meaning our last_buf (when + * != buf) may point to a free:d buffer. + * + * It *shouldn't*, as long as the sizes match... but would + * still be good to find a better solution for this. + */ + if (term->render.last_shm.buf != NULL && + term->render.last_shm.width == buf->width && + term->render.last_shm.height == buf->height && !term->flash.active && !term->render.was_flashing && term->is_searching == term->render.was_searching) { static bool has_warned = false; if (!has_warned) { - LOG_WARN("it appears your Wayland compositor does not support buffer re-use for SHM clients; expect lower performance."); + LOG_WARN( + "it appears your Wayland compositor does not support " + "buffer re-use for SHM clients; expect lower performance."); has_warned = true; } - assert(term->render.last_buf->size == buf->size); - memcpy(buf->mmapped, term->render.last_buf->mmapped, buf->size); + memcpy(buf->mmapped, term->render.last_shm.buf->mmapped, buf->size); } else { @@ -505,7 +513,9 @@ grid_render(struct terminal *term) term_damage_view(term); } - term->render.last_buf = buf; + term->render.last_shm.buf = buf; + term->render.last_shm.width = buf->width; + term->render.last_shm.height = buf->height; term->render.was_flashing = term->flash.active; term->render.was_searching = term->is_searching; } diff --git a/terminal.h b/terminal.h index 11571519..4962aae4 100644 --- a/terminal.h +++ b/terminal.h @@ -276,7 +276,11 @@ struct terminal { struct cell *cell; /* For easy access to content */ } last_cursor; - struct buffer *last_buf; /* Buffer we rendered to last time */ + struct { + struct buffer *buf; /* Buffer we rendered to last time */ + int width; + int height; + } last_shm; bool was_flashing; /* Flash was active last time we rendered */ bool was_searching; } render;