Fixed memory leaks

This commit is contained in:
2026-04-08 14:20:17 +02:00
parent fea5a0ea5f
commit a9dd430cc7
3 changed files with 11 additions and 16 deletions

View File

@@ -85,10 +85,10 @@ pub const Simulator = struct {
std.debug.panic("Failed to remove the road: {}\n", .{err});
};
self.node_man.remove(nodes[0]) catch |err| {
self.node_man.remove(self.allocator, nodes[0]) catch |err| {
std.debug.panic("Failed to remove the first node of the road to be deleted: {}\n", .{err});
};
self.node_man.remove(nodes[1]) catch |err| {
self.node_man.remove(self.allocator, nodes[1]) catch |err| {
std.debug.panic("Failed to remove the second node of the road to be deleted: {}\n", .{err});
};
}
@@ -115,7 +115,7 @@ pub const Simulator = struct {
fn cancelBuildingRoad(self: *Simulator) void {
if (self.node_man.temp_node == null) return;
self.node_man.remove(self.node_man.temp_node.?) catch |err| {
self.node_man.remove(self.allocator, self.node_man.temp_node.?) catch |err| {
std.debug.panic("Node doesn't exist: {}\n", .{err});
};
self.node_man.temp_node = null;
@@ -163,7 +163,7 @@ pub const Simulator = struct {
std.debug.panic("Failed to capture highlighted entity info: {}\n", .{err});
};
rl.drawText(entityInfo, c.WIDTH - (c.TEXT_SIZE / 2) * @as(i32, @intCast(entityInfo.len)), c.TEXT_SIZE, c.TEXT_SIZE, .black);
rl.drawText(entityInfo, c.WIDTH - 30 * @as(i32, @intCast(entityInfo.len)), c.TEXT_SIZE / 2, c.TEXT_SIZE, .black);
}
/// Gets list of pointers of all roads that 'collide' with the road bounded by the nodes we pass into it
@@ -188,13 +188,6 @@ pub const Simulator = struct {
}
}
// TODO verify pointers
// TODO display road/node id
fn verifyPointerIntegrity() void {
}
pub fn update(self: *Simulator) void {
const pos = rl.getMousePosition();
@@ -203,15 +196,15 @@ pub const Simulator = struct {
}
/// Get ID info of the highlighted info and returns it
fn getHighlightedEntityInfo(self: *const Simulator) ![:0]u8 {
var buf: [10 * 1024]u8 = undefined;
fn getHighlightedEntityInfo(self: *const Simulator) ![:0]const u8 {
var buf: [1024]u8 = undefined;
if (self.node_man.highlighted_node) |node|
return std.fmt.bufPrintZ(&buf, "Node ID: {d}\nRoad refs: {d}", .{node.id, node.roads.items.len});
return std.fmt.bufPrintZ(&buf, "Node ID: {d}", .{node.id});
if (self.road_man.highlighted_road) |road|
return std.fmt.bufPrintZ(&buf, "Road ID: {d}", .{road.id});
return std.fmt.bufPrintZ(&buf, "", .{});
return "";
}
};