@@ -24,6 +24,9 @@ const Color = colors.Color;
2424const lit_shader = delve .shaders .default_basic_lighting ;
2525const skinned_lit_shader = delve .shaders .default_skinned_basic_lighting ;
2626
27+ var skinned_shader : graphics.Shader = undefined ;
28+ var static_shader : graphics.Shader = undefined ;
29+
2730var animated_mesh : skinned_mesh.SkinnedMesh = undefined ;
2831var animation : skinned_mesh.PlayingAnimation = undefined ;
2932
@@ -51,7 +54,8 @@ pub fn main() !void {
5154 // See https://github.com/ziglang/zig/issues/19072
5255 try delve .init (std .heap .c_allocator );
5356 } else {
54- try delve .init (gpa .allocator ());
57+ // Using the default allocator will let us detect memory leaks
58+ try delve .init (delve .mem .createDefaultAllocator ());
5559 }
5660
5761 try registerModule ();
@@ -81,17 +85,16 @@ fn on_init() !void {
8185 camera .direction = Vec3 .new (0.0 , 0.0 , 1.0 );
8286
8387 // make shaders for skinned and unskinned meshes
84- const skinned_shader = graphics .Shader .initFromBuiltin (.{ .vertex_attributes = skinned_mesh .getSkinnedShaderAttributes () }, skinned_lit_shader );
85-
86- const static_shader = graphics .Shader .initFromBuiltin (.{ .vertex_attributes = delve .graphics .mesh .getShaderAttributes () }, lit_shader );
88+ skinned_shader = graphics .Shader .initFromBuiltin (.{ .vertex_attributes = skinned_mesh .getSkinnedShaderAttributes () }, skinned_lit_shader ).? ;
89+ static_shader = graphics .Shader .initFromBuiltin (.{ .vertex_attributes = delve .graphics .mesh .getShaderAttributes () }, lit_shader ).? ;
8790
8891 var base_img : images.Image = try images .loadFile (mesh_texture_file );
8992 defer base_img .deinit ();
9093 const tex_base = graphics .Texture .init (& base_img );
9194
9295 // Create a material out of our shader and textures
9396 skinned_mesh_material = try delve .platform .graphics .Material .init (.{
94- .shader = skinned_shader .? ,
97+ .shader = skinned_shader ,
9598 .texture_0 = tex_base ,
9699 .texture_1 = delve .platform .graphics .createSolidTexture (0x00000000 ),
97100
@@ -104,7 +107,7 @@ fn on_init() !void {
104107
105108 // Create a material out of the texture
106109 static_mesh_material = try graphics .Material .init (.{
107- .shader = static_shader .? ,
110+ .shader = static_shader ,
108111 .texture_0 = delve .platform .graphics .createSolidTexture (0xFFFFFFFF ),
109112 .texture_1 = delve .platform .graphics .createSolidTexture (0x00000000 ),
110113
@@ -176,6 +179,12 @@ fn on_draw() void {
176179fn on_cleanup () ! void {
177180 debug .log ("Lighting example module cleaning up" , .{});
178181
182+ skinned_shader .destroy ();
183+ static_shader .destroy ();
184+
185+ skinned_mesh_material .deinit ();
186+ static_mesh_material .deinit ();
187+
179188 animation .deinit ();
180189 animated_mesh .deinit ();
181190}
0 commit comments