use the c allocator when running under valgrind

This commit is contained in:
Mitchell Hashimoto
2022-10-24 15:34:30 -07:00
parent cf14ea506f
commit 9ef431c632
2 changed files with 15 additions and 10 deletions

View File

@ -194,12 +194,14 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
gl.glad.versionMajor(version), gl.glad.versionMajor(version),
gl.glad.versionMinor(version), gl.glad.versionMinor(version),
}); });
if (builtin.mode == .Debug) { // These are very noisy so this is commented, but easy to uncomment
var ext_iter = try gl.ext.iterator(); // whenever we need to check the OpenGL extension list
while (try ext_iter.next()) |ext| { // if (builtin.mode == .Debug) {
log.debug("OpenGL extension available name={s}", .{ext}); // 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) { if (builtin.mode == .Debug) {
// Get our physical DPI - debug only because we don't have a use for // Get our physical DPI - debug only because we don't have a use for

View File

@ -25,10 +25,13 @@ pub fn main() !void {
// faster than GPA. We only do this in release modes so that we // faster than GPA. We only do this in release modes so that we
// can get easy memory leak detection in debug modes. // can get easy memory leak detection in debug modes.
if (builtin.link_libc) { if (builtin.link_libc) {
switch (builtin.mode) { if (switch (builtin.mode) {
.ReleaseSafe, .ReleaseFast => break :gpa std.heap.c_allocator, .ReleaseSafe, .ReleaseFast => true,
else => {},
} // 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 // We don't ever deinit our GPA because the process cleanup will