From 3b35600441265c2a589c8f6e3cbb11c39778b685 Mon Sep 17 00:00:00 2001 From: taliesin-ai Date: Sun, 28 Jun 2026 23:06:09 +1000 Subject: [PATCH] fix(v3/windows): guard FillRect against nil client rect in WM_ERASEBKGND GetClientRect can return nil during minimise/restore transitions; passing that to FillRect crashes. Guard before painting the solid background. Salvaged from #5636 (reported by @sinspired); the rest of that PR was superseded by #5596/#5616. --- v3/UNRELEASED_CHANGELOG.md | 1 + v3/pkg/application/webview_window_windows.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 1803e0e963e..3b62894fe11 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -26,6 +26,7 @@ After processing, the content will be moved to the main changelog and this file - Fix `Menu.Update()` not rebuilding the native menu on GTK4 Linux (#5659, independently diagnosed and fixed by @puneetdixit200 in #5539) - Fix crash enumerating macOS screens on display change by copying screen id/name strings and snapshotting the count (#5565, independently diagnosed and fixed by @x-haose in #5584) +- Fix crash on Windows when `WM_ERASEBKGND` paints a solid background during a minimise/restore transition where `GetClientRect` returns nil (guard reported by @sinspired in #5636) ## Deprecated diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index ad6f44e3d26..0093c9e5377 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -1627,11 +1627,16 @@ func (w *windowsWebviewWindow) WndProc(msg uint32, wparam, lparam uintptr) uintp if w.parent.options.BackgroundType == BackgroundTypeSolid { col := w.parent.options.BackgroundColour hdc := w32.HDC(wparam) - rc := w32.GetClientRect(w.hwnd) - colorRef := w32.COLORREF(uint32(col.Red) | uint32(col.Green)<<8 | uint32(col.Blue)<<16) - hbrush := w32.CreateSolidBrush(colorRef) - w32.FillRect(hdc, rc, hbrush) - w32.DeleteObject(w32.HGDIOBJ(hbrush)) + // GetClientRect can legitimately return nil for a window in a + // transient state (minimise/restore transitions are especially + // prone to triggering it). FillRect with a nil rect crashes, so it + // must be checked before painting. + if rc := w32.GetClientRect(w.hwnd); rc != nil { + colorRef := w32.COLORREF(uint32(col.Red) | uint32(col.Green)<<8 | uint32(col.Blue)<<16) + hbrush := w32.CreateSolidBrush(colorRef) + w32.FillRect(hdc, rc, hbrush) + w32.DeleteObject(w32.HGDIOBJ(hbrush)) + } } return 1 // WM_UAHDRAWMENUITEM is handled by MenuBarWndProc at the top of this function