rules: fix assertion failure

If a view that is currently being destroyed is matched by a newly added
rule river crashes due to an assertion failure.

Fix this and add another assertion to make this precondition more
visible to the users of RuleList.match().
This commit is contained in:
Isaac Freund 2024-02-21 13:34:24 +01:00
parent 53c09be846
commit 9b2d99fa79
No known key found for this signature in database
GPG Key ID: 86DED400DDFD7A11
2 changed files with 4 additions and 0 deletions

View File

@ -183,6 +183,8 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
fn apply_ssd_rules() void {
var it = server.root.views.iterator(.forward);
while (it.next()) |view| {
if (view.destroying) continue;
if (server.config.rules.ssd.match(view)) |ssd| {
view.pending.ssd = ssd;
}

View File

@ -15,6 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
const globber = @import("globber");
@ -98,6 +99,7 @@ pub fn RuleList(comptime T: type) type {
/// Returns the value of the most specific rule matching the view.
/// Returns null if no rule matches.
pub fn match(list: *Self, view: *View) ?T {
assert(!view.destroying);
const app_id = mem.sliceTo(view.getAppId(), 0) orelse "";
const title = mem.sliceTo(view.getTitle(), 0) orelse "";