From a2c81adba0235f48008b8aeaeecfbbe69bcde9a9 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 17 Jun 2021 20:57:14 +0000 Subject: [PATCH] xdg-toplevel: remove listeners before view destroy Currently in handleUnmap() we call View.unmap() before removing listeners. However View.unmap() may destroy the view before returning if the transaction started doesn't have to wait on any configures. To ensure that we don't try to remove listeners which have already been free'd, do this before calling View.unmap(). --- river/Root.zig | 3 +-- river/View.zig | 3 +++ river/XdgToplevel.zig | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/river/Root.zig b/river/Root.zig index a74d0ee..3ea79cf 100644 --- a/river/Root.zig +++ b/river/Root.zig @@ -384,13 +384,12 @@ fn commitTransaction(self: *Self) void { var view_it = output.views.first; while (view_it) |view_node| { const view = &view_node.view; + view_it = view_node.next; if (view.destroying) { - view_it = view_node.next; view.destroy(); continue; } - defer view_it = view_node.next; if (view.pending_serial != null and !view.shouldTrackConfigure()) continue; diff --git a/river/View.zig b/river/View.zig index 816c72e..5b57774 100644 --- a/river/View.zig +++ b/river/View.zig @@ -19,6 +19,7 @@ const Self = @This(); const build_options = @import("build_options"); const std = @import("std"); +const assert = std.debug.assert; const math = std.math; const os = std.os; const wlr = @import("wlroots"); @@ -486,7 +487,9 @@ pub fn map(self: *Self) void { pub fn unmap(self: *Self) void { log.debug("view '{s}' unmapped", .{self.getTitle()}); + assert(!self.destroying); self.destroying = true; + if (self.saved_buffers.items.len == 0) self.saveBuffers(); if (self.opacity_timer != null) { diff --git a/river/XdgToplevel.zig b/river/XdgToplevel.zig index 96b618b..ca360c3 100644 --- a/river/XdgToplevel.zig +++ b/river/XdgToplevel.zig @@ -248,8 +248,6 @@ fn handleMap(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurfa fn handleUnmap(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurface) void { const self = @fieldParentPtr(Self, "unmap", listener); - self.view.unmap(); - // Remove listeners that are only active while mapped self.commit.link.remove(); self.request_fullscreen.link.remove(); @@ -257,6 +255,8 @@ fn handleUnmap(listener: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSur self.request_resize.link.remove(); self.set_title.link.remove(); self.set_app_id.link.remove(); + + self.view.unmap(); } /// Called when the surface is comitted