fixed the "leak". We were de-initializing the allocator before we de-initialized the things allocated with it.
This commit is contained in:
1 parent
fd71b631c4
commit
1140905a4f
7 files changed
+123
-69
No files matched your search
+57
-49
@@ -24,45 +24,53 @@ const screen_height = 720;
|
||||
|
||||
var running: bool = true;
|
||||
|
||||
var dbg_allocator: std.heap.DebugAllocator(.{}) = undefined;
|
||||
const allocator = dbg_allocator.allocator();
|
||||
|
||||
var stdout: *std.io.Writer = undefined;
|
||||
var dbg_allocator = std.heap.DebugAllocator(.{}){};
|
||||
|
||||
// var connection: ?std.net.Stream = undefined;
|
||||
|
||||
pub fn main() !void {
|
||||
std.log.info("Hello Client!", .{});
|
||||
|
||||
try init();
|
||||
const allocator = dbg_allocator.allocator();
|
||||
defer {
|
||||
const deinit_status = dbg_allocator.deinit();
|
||||
if (deinit_status == .leak) {
|
||||
@panic("LEAKED!");
|
||||
} else {
|
||||
// @panic("SUCCESS!");
|
||||
}
|
||||
}
|
||||
|
||||
var stdout = std.fs.File.stdout();
|
||||
|
||||
_ = try stdout.write("Hello, Client!\n");
|
||||
|
||||
try znet.init();
|
||||
defer znet.deinit();
|
||||
rl.setConfigFlags(.{ .window_highdpi = true });
|
||||
rl.setConfigFlags(.{ .window_highdpi = true, .vsync_hint = true });
|
||||
rl.initWindow(screen_width, screen_height, "zzz");
|
||||
defer rl.closeWindow();
|
||||
|
||||
font.ft_lib = try ft.Library.init();
|
||||
|
||||
const sizes = [_]u32{
|
||||
12, 13, 14, 15, 16,
|
||||
18, 20, 22,
|
||||
const sizes = [_]i32{
|
||||
12, 14, 16, 18, 20,
|
||||
};
|
||||
|
||||
var vollkorn: [sizes.len]font.Font = undefined;
|
||||
// var inconsolata: [sizes.len]font.Font = undefined;
|
||||
var inconsolata: [sizes.len]font.Font = undefined;
|
||||
// var arabic: [sizes.len]font.Font = undefined;
|
||||
// var japanese: [sizes.len]font.Font = undefined;
|
||||
|
||||
for (sizes, 0..) |pt, i| {
|
||||
vollkorn[i] = try font.Font.init("assets/fonts/Vollkorn/static/Vollkorn-Regular.ttf", @intCast(pt), allocator);
|
||||
// inconsolata[i] = try font.Font.init("assets/fonts/Inconsolata/static/Inconsolata-Regular.ttf", @intCast(pt), allocator);
|
||||
vollkorn[i] = try font.Font.init("assets/fonts/Vollkorn/static/Vollkorn-Regular.ttf", pt, allocator);
|
||||
inconsolata[i] = try font.Font.init("assets/fonts/Inconsolata/static/Inconsolata-Regular.ttf", @intCast(pt), allocator);
|
||||
// arabic[i] = try font.Font.init("assets/fonts/Noto_Sans_Arabic/static/NotoSansArabic-Regular.ttf", @intCast(pt), allocator);
|
||||
// japanese[i] = try font.Font.init("assets/fonts/Noto_Sans_JP/static/NotoSansJP-Regular.ttf", @intCast(pt), allocator);
|
||||
}
|
||||
|
||||
defer {
|
||||
for (&vollkorn) |*f| f.deinit(allocator);
|
||||
// for (&inconsolata) |*f| f.deinit(allocator);
|
||||
for (&inconsolata) |*f| f.deinit(allocator);
|
||||
// for (&arabic) |*f| f.deinit(allocator);
|
||||
// for (&japanese) |*f| f.deinit(allocator);
|
||||
}
|
||||
@@ -109,10 +117,10 @@ pub fn main() !void {
|
||||
|
||||
// try stdout.flush();
|
||||
|
||||
var the_chunk = try shared.chunk.initChunk(allocator);
|
||||
defer shared.chunk.deinitChunk(&the_chunk, allocator);
|
||||
// var the_chunk = try shared.chunk.initChunk(allocator);
|
||||
// defer shared.chunk.deinitChunk(&the_chunk, allocator);
|
||||
|
||||
shared.chunk.updateChunk(&the_chunk);
|
||||
// shared.chunk.updateChunk(&the_chunk);
|
||||
|
||||
//var elf = entity.Elf.init();
|
||||
|
||||
@@ -204,7 +212,30 @@ pub fn main() !void {
|
||||
|
||||
for (&vollkorn) |*f| {
|
||||
f.render_text(
|
||||
"Whereas, disregard and contempt for human rights have resulted!fi",
|
||||
"Whereas, disregard and contempt for human rights have resulted!",
|
||||
rl.Vector2{ .x = 0, .y = y},
|
||||
true,
|
||||
.white,
|
||||
.blank,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
// const font_ascent : f32 = @floatFromInt(f.face.size().metrics().ascender >> 6);
|
||||
// const dpi_font_ascent = font_ascent / rl.getWindowScaleDPI().y;
|
||||
|
||||
// const font_descent : f32 = @floatFromInt(f.face.size().metrics().descender >> 6);
|
||||
// const dpi_font_descent = font_descent / rl.getWindowScaleDPI().y;
|
||||
|
||||
const font_linegap : f32 = @floatFromInt(f.face.size().metrics().height >> 6);
|
||||
const dpi_font_linegap = font_linegap / rl.getWindowScaleDPI().y;
|
||||
|
||||
y += dpi_font_linegap;
|
||||
}
|
||||
|
||||
for (&inconsolata) |*f| {
|
||||
f.render_text(
|
||||
"Whereas, disregard and contempt for human rights have resulted!",
|
||||
rl.Vector2{ .x = 0, .y = y},
|
||||
true,
|
||||
.white,
|
||||
@@ -216,26 +247,15 @@ pub fn main() !void {
|
||||
const font_ascent : f32 = @floatFromInt(f.face.size().metrics().ascender >> 6);
|
||||
const dpi_font_ascent = font_ascent / rl.getWindowScaleDPI().y;
|
||||
|
||||
y += dpi_font_ascent;
|
||||
const font_descent : f32 = @floatFromInt(f.face.size().metrics().descender >> 6);
|
||||
const dpi_font_descent = font_descent / rl.getWindowScaleDPI().y;
|
||||
|
||||
const font_linegap : f32 = @floatFromInt(f.face.size().metrics().height >> 6);
|
||||
const dpi_font_linegap = font_linegap / rl.getWindowScaleDPI().y;
|
||||
|
||||
y += dpi_font_ascent - dpi_font_descent + dpi_font_linegap;
|
||||
}
|
||||
|
||||
// for (&inconsolata) |*f| {
|
||||
// f.render_text(
|
||||
// "Whereas, disregard and contempt for human rights have resulted!fi",
|
||||
// rl.Vector2{ .x = 0, .y = y},
|
||||
// true,
|
||||
// .white,
|
||||
// .blank,
|
||||
// false,
|
||||
// true
|
||||
// );
|
||||
|
||||
// const font_ascent : f32 = @floatFromInt(f.face.size().metrics().ascender >> 6);
|
||||
// const dpi_font_ascent = font_ascent / rl.getWindowScaleDPI().y;
|
||||
|
||||
// y += dpi_font_ascent;
|
||||
// }
|
||||
|
||||
// for (&japanese) |*f| {
|
||||
// f.render_text(
|
||||
// "外は夜が長くて寒い",
|
||||
@@ -365,7 +385,7 @@ pub fn main() !void {
|
||||
|
||||
//rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white);
|
||||
//rl.drawRectangleLines(0, 0, 100, 100, .red);
|
||||
// misc.drawFPS(0, 0, frame_time, frame);
|
||||
misc.drawFPS(0, 0, frame_time, frame);
|
||||
|
||||
//elf.draw();
|
||||
|
||||
@@ -377,18 +397,6 @@ pub fn main() !void {
|
||||
|
||||
rl.swapScreenBuffer();
|
||||
}
|
||||
|
||||
const deinit_status = dbg_allocator.deinit();
|
||||
if (deinit_status == .leak) std.testing.expect(false) catch @panic("TEST FAIL");
|
||||
}
|
||||
|
||||
fn init() !void {
|
||||
dbg_allocator = std.heap.DebugAllocator(.{}).init;
|
||||
var stdout_buffer: [1024]u8 = undefined;
|
||||
var stdout_writer = std.fs.File.stdout().writer(&stdout_buffer);
|
||||
stdout = &stdout_writer.interface;
|
||||
|
||||
// font.shader = try rl.loadShader(null, "assets/test.frag");
|
||||
}
|
||||
|
||||
fn connect() !void {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -5,7 +5,7 @@ const bufzilla = @import("bufzilla");
|
||||
const shared = @import("shared");
|
||||
const server = @import("server.zig");
|
||||
|
||||
pub fn spawn(chunk: *shared.chunk.Chunk(), comptime T: type, allocator: std.mem.Allocator, value: T) !void {
|
||||
pub fn spawn(chunk: *shared.chunk.Chunk, comptime T: type, allocator: std.mem.Allocator, value: T) !void {
|
||||
std.debug.assert(value.id == shared.entity.INVALID_ID);
|
||||
|
||||
const id = server.next_entity_id;
|
||||
@@ -14,7 +14,7 @@ pub fn spawn(chunk: *shared.chunk.Chunk(), comptime T: type, allocator: std.mem.
|
||||
var entity = value;
|
||||
entity.id = id;
|
||||
|
||||
inline for (@typeInfo(shared.chunk.Chunk()).@"struct".fields) |field| {
|
||||
inline for (@typeInfo(shared.chunk.Chunk).@"struct".fields) |field| {
|
||||
if (field.type == shared.chunk.Storage(T)) {
|
||||
try @field(chunk, field.name).items.append(allocator, entity);
|
||||
break;
|
||||
|
||||
+10
-8
@@ -26,7 +26,9 @@ pub fn Storage(comptime T: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn Chunk() type {
|
||||
pub const Chunk = _Chunk();
|
||||
|
||||
fn _Chunk() type {
|
||||
const FieldCount = entity.EntityKinds.len;
|
||||
|
||||
var fields: [FieldCount]std.builtin.Type.StructField = undefined;
|
||||
@@ -51,10 +53,10 @@ pub fn Chunk() type {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn initChunk(allocator: std.mem.Allocator) !Chunk() {
|
||||
var chunk: Chunk() = undefined;
|
||||
pub fn initChunk(allocator: std.mem.Allocator) !Chunk {
|
||||
var chunk: Chunk = undefined;
|
||||
|
||||
switch (@typeInfo(Chunk())) {
|
||||
switch (@typeInfo(Chunk)) {
|
||||
.@"struct" => |s| {
|
||||
inline for (s.fields) |field| {
|
||||
const StorageT = field.type;
|
||||
@@ -67,8 +69,8 @@ pub fn initChunk(allocator: std.mem.Allocator) !Chunk() {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
pub fn deinitChunk(chunk: *Chunk(), allocator: std.mem.Allocator) void {
|
||||
switch (@typeInfo(Chunk())) {
|
||||
pub fn deinitChunk(chunk: *Chunk, allocator: std.mem.Allocator) void {
|
||||
switch (@typeInfo(Chunk)) {
|
||||
.@"struct" => |s| {
|
||||
inline for (s.fields) |field| {
|
||||
@field(chunk, field.name).deinit(allocator);
|
||||
@@ -78,8 +80,8 @@ pub fn deinitChunk(chunk: *Chunk(), allocator: std.mem.Allocator) void {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn updateChunk(chunk: *Chunk()) void {
|
||||
const info = @typeInfo(Chunk());
|
||||
pub fn updateChunk(chunk: *Chunk) void {
|
||||
const info = @typeInfo(Chunk);
|
||||
|
||||
switch (info) {
|
||||
.@"struct" => |s| {
|
||||
|
||||
Reference in new issue
Block a user