wailsapp/wails · error
Invalid font style
Error message
Invalid font style
What it means
NewFont validates the style bitmask before creating the font: style must be a subset of FontBold|FontItalic|FontUnderline|FontStrikeOut (values 1|2|4|8 = 0x0F). Any style byte with bits above 0x0F — including accidentally passing a point size, a color, or a style enum from a different API — panics with 'Invalid font style'. This is a pure argument-validation panic, not a Win32 failure.
Source
Thrown at v2/internal/frontend/desktop/windows/winc/font.go:36
FontItalic byte = 0x02
FontUnderline byte = 0x04
FontStrikeOut byte = 0x08
)
func init() {
DefaultFont = NewFont("MS Shell Dlg 2", 8, 0)
}
type Font struct {
hfont w32.HFONT
family string
pointSize int
style byte
}
func NewFont(family string, pointSize int, style byte) *Font {
if style > FontBold|FontItalic|FontUnderline|FontStrikeOut {
panic("Invalid font style")
}
//Retrive screen DPI
hDC := w32.GetDC(0)
defer w32.ReleaseDC(0, hDC)
screenDPIY := w32.GetDeviceCaps(hDC, w32.LOGPIXELSY)
font := Font{
family: family,
pointSize: pointSize,
style: style,
}
font.hfont = font.createForDPI(screenDPIY)
if font.hfont == 0 {
panic("CreateFontIndirect failed")
}
View on GitHub (pinned to 0e754b1b40)
Solutions
- Build the style only from winc constants: winc.FontBold, winc.FontItalic, winc.FontUnderline, winc.FontStrikeOut (OR them together)
- Mask the style defensively before the call: style & (FontBold|FontItalic|FontUnderline|FontStrikeOut)
- Double-check the NewFont signature (family string, pointSize int, style byte) when porting code
Example fix
// before
fnt := winc.NewFont("Segoe UI", 9, 12) // 12 = 0b1100 -> only underline(4)+strikeout(8) bits, ok; but 16+ panics
fnt := winc.NewFont("Segoe UI", 9, winc.FontBold|16) // invalid bit -> panic
// after
fnt := winc.NewFont("Segoe UI", 9, winc.FontBold|winc.FontItalic) // subset of 0x0F Defensive patterns
Strategy: validation
Validate before calling
const fontStyleMask = winc.FontBold | winc.FontItalic | winc.FontUnderline | winc.FontStrikeOut // 0x0F
func safeStyle(s byte) byte { return s & fontStyleMask }
fnt := winc.NewFont("Segoe UI", 9, safeStyle(incomingStyle)) Prevention
- Compose styles only from the four winc constants
- When porting font code, re-check the (family, pointSize, style byte) signature
When it happens
Trigger: Calling winc.NewFont(family, size, style) with style > 0x0F, e.g. NewFont("Segoe UI", 9, 16); mixing up parameter order so a size lands in the style slot; OR-ing in a custom flag not defined by winc.
Common situations: Porting font code from other toolkits whose style enums use different bit values; copy-paste parameter-order mistakes (family/pointSize/style swapped).
Related errors
- GetSysColorBrush failed
- Cannot create canvas from invalid HDC.
- CreateFontIndirect failed
- Faild to create solid color brush
- Failed to create null brush
AI-assisted analysis of wailsapp/wails@0e754b1b40 (2026-08-15).
Data as JSON: /api/errors/e5e37715fd753a68.
Report an issue: GitHub.