fixed memory leak in geo

This commit is contained in:
peterino2 2025-09-04 07:32:40 -07:00
parent f271eb856f
commit 386bf94d96
5 changed files with 26 additions and 49 deletions

View File

@ -68,14 +68,18 @@ const EventTimeline = struct {
// warning, due to laziness this uses timelineAllocator, which will leak
pub fn dumpTimeline(filename: []const u8) !void {
if (MTGet()) |tracker| {
core.engine_log("dumping timeline to file {s}", .{filename});
tracker.lock.lock();
defer tracker.lock.unlock();
if (tracker.stackCompactor) |compactor| {
if (tracker.timeline) |timeline| {
core.engine_log("2 {s}", .{filename});
const cwd = std.fs.cwd();
const ofile = try std.fmt.allocPrint(timeline.timelineAllocator, core.DefaultSavePath ++ "/{s}", .{filename});
defer timeline.timelineAllocator.free(ofile);
core.engine_log("1 {s}", .{filename});
var obuf = std.ArrayList(u8).init(timeline.timelineAllocator);
defer obuf.deinit();
var writer = obuf.writer();
@ -116,16 +120,22 @@ pub fn dumpTimeline(filename: []const u8) !void {
}
}
}
core.engine_log("3 {s}", .{filename});
try cwd.makePath(core.DefaultSavePath);
try cwd.writeFile(.{
.sub_path = ofile,
.data = obuf.items,
});
core.engine_log("finished writing", .{});
} else {
core.engine_log("timeline missing", .{});
}
} else {
core.engine_logs("skipping writing memory timeline as timeline is not enabled");
core.engine_logs("skipping writing memory timeline as compactor is not enabled");
}
} else {
core.engine_logs("skipping writing memory timeline as tracker is not enabled");
}
}

View File

@ -422,6 +422,7 @@ pub const Context = struct {
debugText: std.ArrayList([]u8),
debugTextCount: u32 = 0,
drawDebug: bool = false,
rootNodes: std.ArrayList(NodeHandle),
const debugTextMax = 32;
@ -473,6 +474,7 @@ pub const Context = struct {
._horizontalLayout = .{},
.debugText = std.ArrayList([]u8).init(allocator),
.mousePick = Layout.init(allocator),
.rootNodes = std.ArrayList(NodeHandle).init(allocator),
};
for (0..debugTextMax) |_| {
@ -515,6 +517,7 @@ pub const Context = struct {
}
}
}
self.rootNodes.deinit();
self.mousePick.deinit();
@ -817,16 +820,15 @@ pub const Context = struct {
}
}
fn assembleDrawOrderList(self: @This(), list: *DrawOrderList) !void {
var rootNodes = std.ArrayList(NodeHandle).init(self.allocator);
defer rootNodes.deinit();
fn assembleDrawOrderList(self: *@This(), list: *DrawOrderList) !void {
self.rootNodes.clearRetainingCapacity();
var next: NodeHandle = self.getRead(.{}).child;
while (next.index != 0) : (next = self.getRead(next).next) {
if (self.getRead(next).state != .Visible) {
continue;
}
try rootNodes.append(next);
try self.rootNodes.append(next);
}
const SortFunc = struct {
@ -837,12 +839,12 @@ pub const Context = struct {
std.sort.insertion(
NodeHandle,
rootNodes.items,
self,
self.rootNodes.items,
self.*,
SortFunc.lessThan,
);
for (rootNodes.items) |rootNode| {
for (self.rootNodes.items) |rootNode| {
try list.append(rootNode);
try self.assembleDrawOrderListForNode(rootNode, list);
}

View File

@ -135,6 +135,8 @@ pub const TextRenderer = struct {
if (string.len == 0)
return;
try self.geo.resetAllLines();
var indexList = meshBuffer.mapIndexBufferWriter();
var vertexList = meshBuffer.mapVertexBufferWriter();
@ -358,14 +360,6 @@ pub const TextRenderer = struct {
) void {
pass.bindGPUVertexBuffers(0, &.{ .buffer = meshBuffer.vertexBuffer, .offset = 0 }, 1);
pass.bindGPUIndexBuffer(&.{ .buffer = meshBuffer.indexBuffer, .offset = 0 }, .indexelementsize32bit);
// pass.bindGPUFragmentSamplers(0, meshBuffer.fragmentSampler, 1);
//pass.bindGPUFragmentSamplers(0, &.{
//.sampler = rend.context().blockySampler,
//.texture = rend.context().defaultTexture.texture,
//}, 1);
_ = self;
}

View File

@ -309,7 +309,7 @@ pub fn LoadTrenchbroomMap(baseAllocator: std.mem.Allocator, settings: Settings)
try tbMap.addPhysicsShape(solid, settings);
}
physics.context().system.update(0.001, .{}) catch {};
// physics.context().system.update(0.001, .{}) catch {};
// loop over all point entities look for info_player_start
return tbMap;
}

View File

@ -186,6 +186,9 @@ pub const ExternGameObject = struct {
self.tbMap = null;
}
}
if (ig.smallButton("dumpTimeline")) {
core.MemoryTracker.dumpTimeline("timeline.txt") catch unreachable;
}
}
ig.end();
@ -199,38 +202,6 @@ pub const ExternGameObject = struct {
}
}
}
//_ = self;
// imgui.utils.structHexView(self);
// imgui.utils.structHexView(rctx.activeCamera.?);
// if (ig.begin("external game object", null, .{})) {
// ig.textf("sup", .{});
// _ = ig.sliderFloat("skybox strength", &rctx.skyboxSystem.brightnessFactor, 0, 10, null, .{});
// if (rctx.activeCamera) |camera| {
// const forwardVector = camera.forward();
// ig.textf("forward vector x:{d} y:{d} z:{d}", .{ forwardVector.x, forwardVector.y, forwardVector.z });
// }
// }
// ig.end();
// if (ig.begin("list of textures", null, .{})) {
// var iterator = rctx.textureList.map.iterator();
// while (iterator.next()) |i| {
// ig.textf("{s}", .{i.value_ptr.*.name.utf8()});
// }
// }
// ig.end();
// if (ig.begin("list of meshes", null, .{})) {
// ig.textf("number of meshes: {d}", .{rctx.meshPool.installedMeshes.count()});
// var iterator = rctx.meshPool.installedMeshes.iterator();
// while (iterator.next()) |i| {
// ig.textf("{s}", .{i.value_ptr.*.name.utf8()});
// }
// }
// ig.end();
}
pub fn destroy(self: *@This()) void {