{"record":{"id":"44a299ceea1f22df","repo":"wailsapp/wails","slug":"getsyscolorbrush-failed","errorCode":null,"errorMessage":"GetSysColorBrush failed","messagePattern":"GetSysColorBrush failed","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v2/internal/frontend/desktop/windows/winc/brush.go","lineNumber":36,"sourceCode":"\tlogBrush w32.LOGBRUSH\n}\n\nfunc NewSolidColorBrush(color Color) *Brush {\n\tlb := w32.LOGBRUSH{LbStyle: w32.BS_SOLID, LbColor: w32.COLORREF(color)}\n\thBrush := w32.CreateBrushIndirect(&lb)\n\tif hBrush == 0 {\n\t\tpanic(\"Faild to create solid color brush\")\n\t}\n\n\treturn &Brush{hBrush, lb}\n}\n\nfunc NewSystemColorBrush(colorIndex int) *Brush {\n\t//lb := w32.LOGBRUSH{LbStyle: w32.BS_SOLID, LbColor: w32.COLORREF(colorIndex)}\n\tlb := w32.LOGBRUSH{LbStyle: w32.BS_NULL}\n\thBrush := w32.GetSysColorBrush(colorIndex)\n\tif hBrush == 0 {\n\t\tpanic(\"GetSysColorBrush failed\")\n\t}\n\treturn &Brush{hBrush, lb}\n}\n\nfunc NewHatchedColorBrush(color Color) *Brush {\n\tlb := w32.LOGBRUSH{LbStyle: w32.BS_HATCHED, LbColor: w32.COLORREF(color)}\n\thBrush := w32.CreateBrushIndirect(&lb)\n\tif hBrush == 0 {\n\t\tpanic(\"Faild to create solid color brush\")\n\t}\n\n\treturn &Brush{hBrush, lb}\n}\n\nfunc NewNullBrush() *Brush {\n\tlb := w32.LOGBRUSH{LbStyle: w32.BS_NULL}\n\thBrush := w32.CreateBrushIndirect(&lb)\n\tif hBrush == 0 {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/wailsapp/wails/blob/0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3/v2/internal/frontend/desktop/windows/winc/brush.go#L18-L54","documentation":"NewSystemColorBrush wraps GetSysColorBrush and panics when the Win32 call returns NULL for the given system color index. GetSysColorBrush returns NULL only for an out-of-range index; valid indices are the COLOR_* constants 0..30 (COLOR_BTNFACE=15, etc.). Note that the winc default DefaultBackgroundBrush is created at package init with COLOR_BTNFACE, so a bad constant would crash the whole program at import time.","triggerScenarios":"Calling winc.NewSystemColorBrush(n) with an index outside 0..30 (e.g. passing a raw RGB value or a COLORREF instead of a COLOR_* index); passing an index valid on newer Windows versions to an older OS that does not define it.","commonSituations":"Confusing system color indices (int, 0..30) with Color values (RGB); copy-pasting a magic number from docs for a constant the target OS does not support; typo'd constants defined by hand in the w32 package.","solutions":["Pass only w32.COLOR_* constants (COLOR_BTNFACE, COLOR_WINDOW, COLOR_HIGHLIGHT, ...) — never RGB() values — to NewSystemColorBrush","Bounds-check the index against 0..30 before the call (see validation code)","If a system color is unavailable on the target OS, fall back to NewSolidColorBrush with an explicit RGB color instead"],"exampleFix":"// before\nbr := winc.NewSystemColorBrush(0x00FF0000) // RGB mistakenly used as index -> panic\n\n// after\nbr := winc.NewSystemColorBrush(w32.COLOR_BTNFACE) // valid COLOR_* index 0..30","handlingStrategy":"validation","validationCode":"func validSysColorIndex(i int) bool { return i >= 0 && i <= 30 } // COLOR_* range\n\nif validSysColorIndex(idx) {\n    br := winc.NewSystemColorBrush(idx)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass w32.COLOR_* constants; never RGB() values or raw hex","Keep a single named constant list for system colors to avoid magic numbers"],"tags":["windows","gdi","win32-api","winc","panic","invalid-argument"],"backgroundTag":null,"analyzedSha":"0e754b1b40ba9044c2a1460e23b7c3de20fc5cf3","analyzedAt":"2026-08-15T14:17:36.034Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}