Skip to content

Commit

Permalink
Fix leaking textures
Browse files Browse the repository at this point in the history
  • Loading branch information
Deins committed Dec 31, 2024
1 parent 6bedaf8 commit ef5c92f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ zig-cache
.zig-cache
zig-out
*.swp
sdl_files
14 changes: 9 additions & 5 deletions src/dvui.zig
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ const FontCacheEntry = struct {
texture_atlas_size: Size,
texture_atlas_regen: bool,

pub fn deinit(self: *FontCacheEntry) void {
pub fn deinit(self: *FontCacheEntry, win: *Window) void {
if (useFreeType) {
_ = c.FT_Done_Face(self.face);
}
win.backend.textureDestroy(self.texture_atlas);
}

pub const OpenFlags = packed struct(c_int) {
Expand Down Expand Up @@ -624,10 +625,13 @@ pub fn fontCacheGet(font: Font) !*FontCacheEntry {
.texture_atlas_regen = true,
};
}

//log.debug("- size {d} ascent {d} height {d}", .{ font.size, entry.ascent, entry.height });

try cw.font_cache.put(fontHash, entry);
errdefer {
std.debug.assert(false);
textureDestroyLater(entry.texture_atlas);
}
try cw.font_cache.putNoClobber(fontHash, entry);

return cw.font_cache.getPtr(fontHash).?;
}
Expand Down Expand Up @@ -2829,7 +2833,7 @@ pub const Window = struct {
var it = self.font_cache.iterator();
while (it.next()) |item| {
item.value_ptr.glyph_info.deinit();
item.value_ptr.deinit();
item.value_ptr.deinit(self);
}
self.font_cache.deinit();
}
Expand Down Expand Up @@ -3454,7 +3458,7 @@ pub const Window = struct {
for (deadFonts.items) |id| {
var tce = self.font_cache.fetchRemove(id).?;
tce.value.glyph_info.deinit();
tce.value.deinit();
tce.value.deinit(self);
}

//std.debug.print("font_cache {d}\n", .{self.font_cache.count()});
Expand Down

1 comment on commit ef5c92f

@david-vanderson
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please sign in to comment.