Skip to content

Commit

Permalink
fix parser handling of glyph shape freeing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed94 committed Jan 11, 2025
1 parent b78a544 commit e8a7b21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 4 additions & 4 deletions vefontcache/draw.odin
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
error : Allocator_Error
glyph.shape, error = parser_get_glyph_shape(entry.parser_info, shape.glyph[id])
assert(error == .None)
assert(glyph.shape != nil)
assert(len(glyph.shape) > 0)

generate_glyph_pass_draw_list( draw_list, & glyph_buffer.shape_gen_scratch,
glyph_pack[id].shape,
Expand All @@ -621,7 +621,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
glyph_pack[id].draw_transform.scale
)

assert(glyph.shape != nil)
assert(len(glyph.shape) > 0)
parser_free_shape(entry.parser_info, glyph.shape)

target_quad := & glyph_pack[id].draw_quad
Expand Down Expand Up @@ -736,7 +736,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
error : Allocator_Error
glyph.shape, error = parser_get_glyph_shape(entry.parser_info, shape.glyph[id])
assert(error == .None)
assert(glyph.shape != nil)
assert(len(glyph.shape) > 0)

// Render glyph to glyph render target (FBO)
generate_glyph_pass_draw_list( draw_list, & glyph_buffer.shape_gen_scratch,
Expand All @@ -747,7 +747,7 @@ batch_generate_glyphs_draw_list :: proc ( draw_list : ^Draw_List,
glyph.draw_transform.scale
)

assert(glyph.shape != nil)
assert(len(glyph.shape) > 0)
parser_free_shape(entry.parser_info, glyph.shape)
}

Expand Down
8 changes: 5 additions & 3 deletions vefontcache/parser.odin
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ parser_find_glyph_index :: #force_inline proc "contextless" ( font : Parser_Font

parser_free_shape :: #force_inline proc( font : Parser_Font_Info, shape : Parser_Glyph_Shape )
{
stbtt.FreeShape( font.stbtt_info, transmute( [^]stbtt.vertex) raw_data(shape) )
shape := shape
shape_raw := transmute( ^Raw_Dynamic_Array) & shape
stbtt.FreeShape( font.stbtt_info, transmute( [^]stbtt.vertex) shape_raw.data )
}

parser_get_codepoint_horizontal_metrics :: #force_inline proc "contextless" ( font : Parser_Font_Info, codepoint : rune ) -> ( advance, to_left_side_glyph : i32 )
Expand Down Expand Up @@ -166,11 +168,11 @@ parser_get_glyph_shape :: #force_inline proc ( font : Parser_Font_Info, glyph_in
stb_shape : [^]stbtt.vertex
nverts := stbtt.GetGlyphShape( font.stbtt_info, cast(i32) glyph_index, & stb_shape )

shape_raw := transmute( ^runtime.Raw_Dynamic_Array) & shape
shape_raw := transmute( ^Raw_Dynamic_Array) & shape
shape_raw.data = stb_shape
shape_raw.len = int(nverts)
shape_raw.cap = int(nverts)
shape_raw.allocator = runtime.nil_allocator()
shape_raw.allocator = nil_allocator()
error = Allocator_Error.None
return
}
Expand Down

0 comments on commit e8a7b21

Please sign in to comment.