main: fix tracy allocator in GlobalState

This commit is contained in:
Mitchell Hashimoto
2023-02-19 11:11:06 -08:00
parent 73de43f169
commit d8dd0be32a

View File

@ -173,6 +173,7 @@ pub const GlobalState = struct {
gpa: ?GPA,
alloc: std.mem.Allocator,
tracy: if (tracy.enabled) ?tracy.Allocator(null) else void,
pub fn init(self: *GlobalState) void {
// Output some debug information right away
@ -194,6 +195,7 @@ pub const GlobalState = struct {
self.* = .{
.gpa = null,
.alloc = undefined,
.tracy = undefined,
};
errdefer self.deinit();
@ -224,8 +226,8 @@ pub const GlobalState = struct {
// If we're tracing, wrap the allocator
if (!tracy.enabled) break :alloc base;
var tracy_alloc = tracy.allocator(base, null);
break :alloc tracy_alloc.allocator();
self.tracy = tracy.allocator(base, null);
break :alloc self.tracy.?.allocator();
};
}
@ -237,6 +239,10 @@ pub const GlobalState = struct {
// the point at which it will output if there were safety violations.
_ = value.deinit();
}
if (tracy.enabled) {
self.tracy = null;
}
}
};
test {