mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Fix Windows crash bug (#4460)
* ## Summary I've successfully fixed the nil pointer dereference bug in the Wails v3 system tray functionality on Windows. Here's what I addressed: **Root Cause**: The bug occurred in `systemtray_windows.go:80` where `*trayBounds = PhysicalToDipRect(*trayBounds)` was dereferencing a potentially nil pointer without checking. **Fixes Applied**: 1. **`positionWindow` method (lines 80-82)**: Added nil check for `trayBounds` before dereferencing 2. **`bounds` method (lines 121-123, 129-131)**: Added checks for uninitialized `hwnd` and nil return from `GetSystrayBounds` 3. **`iconIsInTrayBounds` method (lines 147-149, 155-157, 160-162)**: Added similar protective checks and taskbar position validation 4. **`getScreen` method (lines 173-175)**: Added `hwnd` initialization check 5. **`openMenu` method (lines 45-47)**: Added nil check for `trayBounds` **Key Improvements**: - Added proper initialization checks for `s.hwnd == 0` - Added nil pointer checks for all Windows API return values - Ensured graceful error handling instead of panics - Maintained existing functionality while preventing race conditions The fix addresses the race condition where system tray operations could be called before the tray was fully initialized, preventing the nil pointer dereference panic described in issue #4456. * Update changelog
This commit is contained in:
parent
10447e6fcd
commit
d863e525e3
2 changed files with 30 additions and 0 deletions
|
|
@ -27,6 +27,10 @@ After processing, the content will be moved to the main changelog and this file
|
|||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
- Fix Windows nil pointer dereference bug reported in [#4456](https://github.com/wailsapp/wails/issues/4456) by @leaanthony in [#4460](https://github.com/wailsapp/wails/pull/4460)
|
||||
- Add support for `allowsBackForwardNavigationGestures` in macOS WKWebView to enable two-finger swipe navigation gestures (#1857)
|
||||
- Fixes issue where onClick didn't work for menu items initially set as disabled by @leaanthony in [PR #4469](https://github.com/wailsapp/wails/pull/4469). Thanks to @IanVS for the initial investigation.
|
||||
- Fix Vite server not being cleaned up when build fails (#4403)
|
||||
- Fixed panic when closing or cancelling a `SaveFileDialog` on windows. Fixed in [PR](https://github.com/wailsapp/wails/pull/4284) by @hkhere
|
||||
- Fixed HTML level drag and drop on Windows by [@mbaklor](https://github.com/mbaklor) in [#4259](https://github.com/wailsapp/wails/pull/4259)
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ func (s *windowsSystemTray) openMenu() {
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
if trayBounds == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Show the menu at the tray bounds
|
||||
s.menu.ShowAt(trayBounds.X, trayBounds.Y)
|
||||
|
|
@ -77,6 +80,9 @@ func (s *windowsSystemTray) positionWindow(window *WebviewWindow, offset int) er
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if trayBounds == nil {
|
||||
return errors.New("failed to get system tray bounds")
|
||||
}
|
||||
*trayBounds = PhysicalToDipRect(*trayBounds)
|
||||
centerAlignX = trayBounds.X + (trayBounds.Width / 2) - (windowBounds.Width / 2)
|
||||
centerAlignY = trayBounds.Y + (trayBounds.Height / 2) - (windowBounds.Height / 2)
|
||||
|
|
@ -115,10 +121,17 @@ func (s *windowsSystemTray) positionWindow(window *WebviewWindow, offset int) er
|
|||
}
|
||||
|
||||
func (s *windowsSystemTray) bounds() (*Rect, error) {
|
||||
if s.hwnd == 0 {
|
||||
return nil, errors.New("system tray window handle not initialized")
|
||||
}
|
||||
|
||||
bounds, err := w32.GetSystrayBounds(s.hwnd, s.uid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if bounds == nil {
|
||||
return nil, errors.New("GetSystrayBounds returned nil")
|
||||
}
|
||||
|
||||
monitor := w32.MonitorFromWindow(s.hwnd, w32.MONITOR_DEFAULTTONEAREST)
|
||||
if monitor == 0 {
|
||||
|
|
@ -134,12 +147,22 @@ func (s *windowsSystemTray) bounds() (*Rect, error) {
|
|||
}
|
||||
|
||||
func (s *windowsSystemTray) iconIsInTrayBounds() (bool, error) {
|
||||
if s.hwnd == 0 {
|
||||
return false, errors.New("system tray window handle not initialized")
|
||||
}
|
||||
|
||||
bounds, err := w32.GetSystrayBounds(s.hwnd, s.uid)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if bounds == nil {
|
||||
return false, errors.New("GetSystrayBounds returned nil")
|
||||
}
|
||||
|
||||
taskbarRect := w32.GetTaskbarPosition()
|
||||
if taskbarRect == nil {
|
||||
return false, errors.New("failed to get taskbar position")
|
||||
}
|
||||
|
||||
inTasksBar := w32.RectInRect(bounds, &taskbarRect.Rc)
|
||||
if inTasksBar {
|
||||
|
|
@ -150,6 +173,9 @@ func (s *windowsSystemTray) iconIsInTrayBounds() (bool, error) {
|
|||
}
|
||||
|
||||
func (s *windowsSystemTray) getScreen() (*Screen, error) {
|
||||
if s.hwnd == 0 {
|
||||
return nil, errors.New("system tray window handle not initialized")
|
||||
}
|
||||
// Get the screen for this systray
|
||||
return getScreenForWindowHwnd(s.hwnd)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue