Skip to content

fix: don't panic on whitespace glyphs; mark FT_BitmapGlyph cast unsafe#4

Open
MartenH wants to merge 2 commits into
vlang:mainfrom
MartenH:fix/whitespace-glyph-empty-outline
Open

fix: don't panic on whitespace glyphs; mark FT_BitmapGlyph cast unsafe#4
MartenH wants to merge 2 commits into
vlang:mainfrom
MartenH:fix/whitespace-glyph-empty-outline

Conversation

@MartenH

@MartenH MartenH commented Jun 9, 2026

Copy link
Copy Markdown

Two small fixes found while bringing up vglyph on a native-Windows build (mingw-w64 / gcc 16), but neither is Windows-specific.

1. Don't panic on whitespace glyphs with empty outlines

Whitespace glyphs such as U+0020 SPACE legitimately load with an empty outline (n_points == 0). In the subpixel-shift path, load_glyph() panicked on this in debug builds:

FT_Outline_Translate requires loaded outline, got empty. Check FT_Load_Glyph flags.

So any text containing a space aborts a debug build. FT_Outline_Translate on an empty outline is a no-op anyway, so this guards the translate on n_points > 0 and drops the panic. Release builds already called FT_Outline_Translate unconditionally; this just makes the empty case explicit and removes the debug-only abort.

2. Wrap the FT_BitmapGlyphRec pointer cast in unsafe

load_stroked_glyph() casts &C.FT_GlyphRec&C.FT_BitmapGlyphRec, a pointer-type cast that V warns about outside an unsafe block. Wrapped in unsafe {} to make the intent explicit and silence the warning, consistent with the other C-interop pointer casts in the module.

Both changes are v fmt-clean. Verified by building a vglyph-based GUI app on both Linux and native Windows.

MartenH added 2 commits June 9, 2026 16:30
Whitespace glyphs such as U+0020 SPACE legitimately load with an empty
outline (n_points == 0). load_glyph() panicked on this in debug builds
("FT_Outline_Translate requires loaded outline, got empty"), so any text
containing a space aborted a debug build.

FT_Outline_Translate on an empty outline is a no-op anyway, so guard the
translate on n_points > 0 and drop the panic. Release builds already
called FT_Outline_Translate unconditionally; this just makes the empty
case explicit and stops the debug-only abort.
Casting &C.FT_GlyphRec to &C.FT_BitmapGlyphRec is a pointer-type cast,
which V flags with a warning outside an unsafe block. Wrap it in unsafe {}
to make the intent explicit and silence the warning, consistent with the
other C-interop pointer casts in this module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant