{mach,examples}: Fix memory leaks (#384)
This commit is contained in:
parent
39e07df150
commit
858c14bbae
2 changed files with 5 additions and 1 deletions
|
|
@ -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"),
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue