fixing leaks
Build / build (push) Successful in 1m15s
Test / build_and_test (push) Has been cancelled

This commit is contained in:
2026-05-06 12:55:41 +02:00
parent 4f0ada9034
commit 29cdf44233
6 changed files with 30 additions and 14 deletions
+1 -1
View File
@@ -86,8 +86,8 @@ pub fn create(device: *base.Device, allocator: std.mem.Allocator, info: *const v
pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) void {
const self: *Self = @alignCast(@fieldParentPtr("interface", interface));
allocator.destroy(self);
_ = self.command_allocator.reset(.free_all);
allocator.destroy(self);
}
pub fn execute(self: *Self, device: *ExecutionDevice) void {
+2 -1
View File
@@ -96,8 +96,9 @@ pub fn destroy(interface: *Interface, allocator: std.mem.Allocator) VkError!void
if (!self.device_allocator.detectLeaks()) {
std.log.scoped(.vkDestroyDevice).debug("No device memory leaks detected", .{});
}
allocator.destroy(self);
}
allocator.destroy(self);
}
pub fn allocateMemory(interface: *Interface, allocator: std.mem.Allocator, info: *const vk.MemoryAllocateInfo) VkError!*base.DeviceMemory {
+5 -2
View File
@@ -58,13 +58,16 @@ pub fn submit(interface: *Interface, infos: []Interface.SubmitInfo, p_fence: ?*b
const allocator = soft_device.device_allocator.allocator();
const io = soft_device.interface.io();
const runners_counter = allocator.create(RefCounter) catch return VkError.OutOfDeviceMemory;
errdefer allocator.destroy(runners_counter);
runners_counter.* = .init;
runners_counter.setRef(infos.len);
for (infos) |info| {
// Cloning info to keep them alive until command execution ends
const cloned_info: Interface.SubmitInfo = .{
.command_buffers = info.command_buffers.clone(allocator) catch return VkError.OutOfDeviceMemory,
};
const runners_counter = allocator.create(RefCounter) catch return VkError.OutOfDeviceMemory;
runners_counter.* = .init;
self.group.async(io, Self.taskRunner, .{ self, cloned_info, p_fence, runners_counter });
}
}
+14 -7
View File
@@ -57,8 +57,8 @@ pub fn allocateCommandBuffers(self: *Self, info: *const vk.CommandBufferAllocate
}
for (0..info.command_buffer_count) |_| {
const cmd = try self.vtable.createCommandBuffer(self, allocator, info);
const non_dis_cmd = try Dispatchable(CommandBuffer).wrap(allocator, cmd);
self.buffers.appendAssumeCapacity(non_dis_cmd);
const dis_cmd = try Dispatchable(CommandBuffer).wrap(allocator, cmd);
self.buffers.appendAssumeCapacity(dis_cmd);
}
}
@@ -85,20 +85,27 @@ pub fn freeCommandBuffers(self: *Self, cmds: []*Dispatchable(CommandBuffer)) VkE
}
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
for (self.buffers.items) |non_dis_cmd| {
non_dis_cmd.intrusiveDestroy(allocator);
for (self.buffers.items) |dis_cmd| {
dis_cmd.intrusiveDestroy(allocator);
}
self.buffers.deinit(allocator);
self.vtable.destroy(self, allocator);
}
pub inline fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
pub fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
try self.vtable.reset(self, flags);
self.first_free_buffer_index = 0;
if (flags.release_resources_bit) {
const allocator = self.host_allocator.allocator();
for (self.buffers.items) |non_dis_cmd| {
non_dis_cmd.intrusiveDestroy(allocator);
for (self.buffers.items) |dis_cmd| {
dis_cmd.intrusiveDestroy(allocator);
}
self.buffers.clearRetainingCapacity();
} else {
for (self.buffers.items) |dis_cmd| {
_ = dis_cmd.object.reset(.{ .release_resources_bit = true }) catch {};
}
}
}
+4
View File
@@ -10,6 +10,10 @@ pub inline fn ref(self: *Self) void {
_ = self.count.fetchAdd(1, .seq_cst);
}
pub inline fn setRef(self: *Self, count: usize) void {
_ = self.count.store(count, .seq_cst);
}
pub inline fn unref(self: *Self) void {
_ = self.count.fetchSub(1, .seq_cst);
}
+3 -2
View File
@@ -103,11 +103,12 @@ pub fn detachSurface(self: *Self) VkError!void {
}
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
if (self.surface) |surface| {
for (self.images) |*image| {
if (self.surface) |surface| {
surface.detachImage(allocator, image) catch {};
}
image.deinit(allocator);
}
}
allocator.free(self.images);
allocator.destroy(self);
}