From dd1302a711fc4b8967eb2096dbe7132224460e8d Mon Sep 17 00:00:00 2001 From: lkn Date: Tue, 23 Jun 2026 20:35:31 +0200 Subject: [PATCH] fix titlebar resize: detach buffer from scene before replacing Call wlr_scene_buffer_set_buffer(NULL) before freeing the old pixman image so the scene graph cannot access freed data. Re-register the backing table entry after creating the new image. --- src/backend/wayland/wl_framebuf.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/backend/wayland/wl_framebuf.c b/src/backend/wayland/wl_framebuf.c index 655f741..2bfea5e 100644 --- a/src/backend/wayland/wl_framebuf.c +++ b/src/backend/wayland/wl_framebuf.c @@ -578,12 +578,22 @@ wl_frame_paint(struct WFrameWindow *fwin) wlr_scene_node_set_position(&tb_fb->scene_buf->node, 0, 0); } - /* If titlebar buffer is too narrow, draw into parent frame instead - * to avoid replacing the pixman image while the scene graph may still - * hold a reference to the old wlr_buffer data. */ + /* Resize titlebar buffer if too narrow — detach from scene graph + * first so the old pixel data isn't accessed after being freed. */ if (tb_fb && tb_fb->width < tb_w) { - tb_img = fb->image; - tb_fb = NULL; + if (tb_fb->scene_buf) + wlr_scene_buffer_set_buffer(tb_fb->scene_buf, NULL); + pixman_image_unref(tb_fb->image); + tb_fb->image = pixman_image_create_bits(PIXMAN_a8r8g8b8, + tb_w, tb_h, NULL, 0); + tb_fb->width = tb_w; + tb_fb->height = tb_h; + tb_fb->base.width = tb_w; + tb_fb->base.height = tb_h; + tb_img = tb_fb->image; + W_RegisterBacking(tb_fb->id, tb_fb->image); + if (tb_fb->scene_buf) + wlr_scene_buffer_set_dest_size(tb_fb->scene_buf, tb_w, tb_h); } WTexture *tex = fwin->title_texture[state];