View: add more assertions around destruction
This should make leaks like the one fixed by the previous commit harder to write.
This commit is contained in:
parent
a374c6ab84
commit
94828474b0
@ -726,7 +726,7 @@ fn commitTransaction(root: *Root) void {
|
||||
var it = root.hidden.inflight.focus_stack.safeIterator(.forward);
|
||||
while (it.next()) |view| {
|
||||
view.dropSavedSurfaceTree();
|
||||
if (view.destroying) view.destroy();
|
||||
if (view.destroying) view.destroy(.assert);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -228,8 +228,9 @@ pub fn create(impl: Impl) error{OutOfMemory}!*View {
|
||||
/// If saved buffers of the view are currently in use by a transaction,
|
||||
/// mark this view for destruction when the transaction completes. Otherwise
|
||||
/// destroy immediately.
|
||||
pub fn destroy(view: *View) void {
|
||||
pub fn destroy(view: *View, when: enum { lazy, assert }) void {
|
||||
assert(view.impl == .none);
|
||||
assert(!view.mapped);
|
||||
|
||||
view.destroying = true;
|
||||
|
||||
@ -249,6 +250,11 @@ pub fn destroy(view: *View) void {
|
||||
if (view.output_before_evac) |name| util.gpa.free(name);
|
||||
|
||||
util.gpa.destroy(view);
|
||||
} else {
|
||||
switch (when) {
|
||||
.lazy => {},
|
||||
.assert => unreachable,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
|
||||
.view = undefined,
|
||||
.wlr_toplevel = wlr_toplevel,
|
||||
} });
|
||||
errdefer view.destroy();
|
||||
errdefer view.destroy(.assert);
|
||||
|
||||
const toplevel = &view.impl.toplevel;
|
||||
|
||||
@ -219,7 +219,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
|
||||
const view = toplevel.view;
|
||||
view.impl = .none;
|
||||
view.destroy();
|
||||
view.destroy(.lazy);
|
||||
}
|
||||
|
||||
fn handleMap(listener: *wl.Listener(void)) void {
|
||||
|
@ -64,7 +64,7 @@ pub fn create(xwayland_surface: *wlr.XwaylandSurface) error{OutOfMemory}!void {
|
||||
.view = undefined,
|
||||
.xwayland_surface = xwayland_surface,
|
||||
} });
|
||||
errdefer view.destroy();
|
||||
errdefer view.destroy(.assert);
|
||||
|
||||
const xwayland_view = &view.impl.xwayland_view;
|
||||
xwayland_view.view = view;
|
||||
@ -142,7 +142,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
|
||||
const view = xwayland_view.view;
|
||||
view.impl = .none;
|
||||
view.destroy();
|
||||
view.destroy(.lazy);
|
||||
}
|
||||
|
||||
fn handleAssociate(listener: *wl.Listener(void)) void {
|
||||
|
Loading…
Reference in New Issue
Block a user