Skip to content

Fix Windows crash bug - #4460

Merged
leaanthony merged 4 commits into
v3-alphafrom
vk-5b54-fix-this-b
Aug 4, 2025
Merged

leaanthony merged 4 commits into
v3-alphafrom
vk-5b54-fix-this-b

Conversation

@leaanthony

@leaanthony leaanthony commented Jul 29, 2025 •

Copy link
Copy Markdown
Member

Initial attempt at fixing the nil dereference bug

closes #4456

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for system tray operations on Windows, reducing the likelihood of crashes when system tray state is invalid or uninitialized. Users may now see clearer error messages if issues occur with the system tray.
    • Fixed navigation gestures support on macOS WKWebView for two-finger swipes.
    • Resolved an issue where clicking initially disabled menu items did not trigger actions.
    • Addressed cleanup of the Vite server after build failures to prevent lingering processes.

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.
@coderabbitai

coderabbitai Bot commented Jul 29, 2025 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@dosubot[bot] has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 29 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between c0f8260 and d303fa7.

📒 Files selected for processing (1)
  • v3/UNRELEASED_CHANGELOG.md (1 hunks)

Walkthrough

Defensive error handling has been added to several methods in the Windows system tray implementation. The updates introduce explicit nil checks and error returns for uninitialized or unavailable system tray bounds, handles, and related resources, aiming to prevent nil pointer dereferences and clarify error reporting in internal logic.

Changes

Cohort / File(s) Change Summary
Defensive Error Handling in System Tray Methods
v3/pkg/application/systemtray_windows.go
Added nil checks and error returns in multiple methods to handle uninitialized tray bounds, handles, and taskbar positions; improved internal error reporting and prevention of nil dereferences.
Changelog Update
v3/UNRELEASED_CHANGELOG.md
Updated changelog with new fixed issues including the Windows nil pointer dereference bug fix and other unrelated fixes for macOS gestures, menu item clicks, and Vite server cleanup.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Assessment against linked issues

Objective Addressed Explanation
Prevent nil pointer dereference panic in windowsSystemTray.positionWindow (#4456) ✅

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Addition of changelog entries for macOS gestures, menu item click fixes, and Vite server cleanup (v3/UNRELEASED_CHANGELOG.md) These changes are unrelated to the Windows system tray nil pointer dereference issue (#4456).

Suggested labels

v3, size:M, lgtm

Poem

A rabbit hops near Windows' tray,
Checks for nils along the way.
No pointer traps or hidden snare,
Just careful bounds and handled care.
With every hop, a safer code—
The tray now guards its precious load!
🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch vk-5b54-fix-this-b

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jul 29, 2025
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Missing Changelog Update

Hi @leaanthony, please update v3/UNRELEASED_CHANGELOG.md with a description of your changes.

This helps us keep track of changes for the next release.

@dosubot dosubot Bot added Bug Something isn't working go Pull requests that update Go code labels Jul 29, 2025
@leaanthony leaanthony changed the title Fix this bug Fix Linux crash bug Jul 29, 2025
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 29, 2025 •

Copy link
Copy Markdown

Deploying wails with  Cloudflare Pages  Cloudflare Pages

Latest commit: d303fa7
Status:⚡️  Build in progress...

View logs

@leaanthony leaanthony changed the title Fix Linux crash bug Fix Windows crash bug Jul 29, 2025
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Aug 2, 2025
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Aug 4, 2025
@leaanthony
leaanthony merged commit d863e52 into v3-alpha Aug 4, 2025
@leaanthony
leaanthony deleted the vk-5b54-fix-this-b branch August 4, 2025 10:45
@sonarqubecloud

sonarqubecloud Bot commented Aug 4, 2025

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot mentioned this pull request Oct 22, 2025
6 of 15 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Feb 13, 2026
13 tasks done
Grantmartin2002 pushed a commit to Grantmartin2002/wails that referenced this pull request Apr 29, 2026
* ## 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 wailsapp#4456.

* Update changelog
@taliesin-ai taliesin-ai added v3 and removed v3-alpha labels Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Documentation Improvements or additions to documentation go Pull requests that update Go code size:M This PR changes 30-99 lines, ignoring generated files. v3 Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants