{mach,examples}: Fix memory leaks (#384)

This commit is contained in:
Ayush 2022-07-03 21:17:47 +05:30 committed by GitHub
parent 39e07df150
commit 858c14bbae
Failed to generate hash of commit
2 changed files with 5 additions and 1 deletions

View file

@ -116,6 +116,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
}); });
const queue = engine.device.getQueue(); const queue = engine.device.getQueue();
const img = try zigimg.Image.fromMemory(engine.allocator, @embedFile("../assets/gotta-go-fast.png")); const img = try zigimg.Image.fromMemory(engine.allocator, @embedFile("../assets/gotta-go-fast.png"));
defer img.deinit();
const img_size = gpu.Extent3D{ .width = @intCast(u32, img.width), .height = @intCast(u32, img.height) }; const img_size = gpu.Extent3D{ .width = @intCast(u32, img.width), .height = @intCast(u32, img.height) };
const cube_texture = engine.device.createTexture(&.{ const cube_texture = engine.device.createTexture(&.{
.size = img_size, .size = img_size,
@ -134,7 +135,7 @@ pub fn init(app: *App, engine: *mach.Engine) !void {
.Rgba32 => |pixels| queue.writeTexture(&.{ .texture = cube_texture }, &data_layout, &img_size, zigimg.color.Rgba32, pixels), .Rgba32 => |pixels| queue.writeTexture(&.{ .texture = cube_texture }, &data_layout, &img_size, zigimg.color.Rgba32, pixels),
.Rgb24 => |pixels| { .Rgb24 => |pixels| {
const data = try rgb24ToRgba32(engine.allocator, pixels); const data = try rgb24ToRgba32(engine.allocator, pixels);
//defer data.deinit(allocator); defer data.deinit(engine.allocator);
queue.writeTexture(&.{ .texture = cube_texture }, &data_layout, &img_size, zigimg.color.Rgba32, data.Rgba32); queue.writeTexture(&.{ .texture = cube_texture }, &data_layout, &img_size, zigimg.color.Rgba32, data.Rgba32);
}, },
else => @panic("unsupported image color format"), else => @panic("unsupported image color format"),

View file

@ -205,6 +205,9 @@ pub const Platform = struct {
cur.destroy(); cur.destroy();
} }
} }
while (platform.events.popFirst()) |ev| {
platform.allocator.destroy(ev);
}
} }
fn pushEvent(platform: *Platform, event: structs.Event) void { fn pushEvent(platform: *Platform, event: structs.Event) void {