Skip to content

Commit 17ced09

Browse files
committed
Fixing up leaks in the rays example
1 parent 48cf53b commit 17ced09

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/examples/rays.zig

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn main() !void {
2424
.init_fn = on_init,
2525
.tick_fn = on_tick,
2626
.draw_fn = on_draw,
27+
.cleanup_fn = on_cleanup,
2728
};
2829

2930
// Pick the allocator to use depending on platform
@@ -33,7 +34,8 @@ pub fn main() !void {
3334
// See https://github.com/ziglang/zig/issues/19072
3435
try delve.init(std.heap.c_allocator);
3536
} else {
36-
try delve.init(gpa.allocator());
37+
// Using the default allocator will let us detect memory leaks
38+
try delve.init(delve.mem.createDefaultAllocator());
3739
}
3840

3941
try delve.modules.registerModule(example);
@@ -48,6 +50,7 @@ pub fn on_init() !void {
4850
// Create some materials
4951
material_frustum = try delve.platform.graphics.Material.init(.{
5052
.shader = shader,
53+
.own_shader = true,
5154
.texture_0 = delve.platform.graphics.createSolidTexture(0x66FFFFFF),
5255
.cull_mode = .NONE,
5356
.depth_write_enabled = false,
@@ -141,3 +144,15 @@ pub fn on_draw() void {
141144

142145
ray_mesh.draw(view_mats, delve.math.Mat4.rotate(time * 10.0, delve.math.Vec3.up));
143146
}
147+
148+
pub fn on_cleanup() !void {
149+
material_frustum.deinit();
150+
material_cube.deinit();
151+
material_highlight.deinit();
152+
material_hitpoint.deinit();
153+
154+
frustum_mesh.deinit();
155+
cube_mesh.deinit();
156+
hit_mesh.deinit();
157+
ray_mesh.deinit();
158+
}

0 commit comments

Comments
 (0)