From 9ef431c632cb931ecaf1409e88a63217ba52df8a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 24 Oct 2022 15:34:30 -0700 Subject: [PATCH] use the c allocator when running under valgrind --- src/Window.zig | 14 ++++++++------ src/main.zig | 11 +++++++---- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Window.zig b/src/Window.zig index 91b82b8af..71b3dac29 100644 --- a/src/Window.zig +++ b/src/Window.zig @@ -194,12 +194,14 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo gl.glad.versionMajor(version), gl.glad.versionMinor(version), }); - if (builtin.mode == .Debug) { - var ext_iter = try gl.ext.iterator(); - while (try ext_iter.next()) |ext| { - log.debug("OpenGL extension available name={s}", .{ext}); - } - } + // These are very noisy so this is commented, but easy to uncomment + // whenever we need to check the OpenGL extension list + // if (builtin.mode == .Debug) { + // var ext_iter = try gl.ext.iterator(); + // while (try ext_iter.next()) |ext| { + // log.debug("OpenGL extension available name={s}", .{ext}); + // } + // } if (builtin.mode == .Debug) { // Get our physical DPI - debug only because we don't have a use for diff --git a/src/main.zig b/src/main.zig index 990d1f354..076b75e8b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -25,10 +25,13 @@ pub fn main() !void { // faster than GPA. We only do this in release modes so that we // can get easy memory leak detection in debug modes. if (builtin.link_libc) { - switch (builtin.mode) { - .ReleaseSafe, .ReleaseFast => break :gpa std.heap.c_allocator, - else => {}, - } + if (switch (builtin.mode) { + .ReleaseSafe, .ReleaseFast => true, + + // We also use it if we can detect we're running under + // Valgrind since Valgrind only instruments the C allocator + else => std.valgrind.runningOnValgrind() > 0, + }) break :gpa std.heap.c_allocator; } // We don't ever deinit our GPA because the process cleanup will