Skip to content

Prevent process crashes from unhandled exceptions in global keyboard hook callback - #10

Closed
0RuiAlvel0 with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-frequent-app-crashes
Closed

0RuiAlvel0 with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-frequent-app-crashes

Conversation

Copilot AI commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Users reported frequent hard crashes that surfaced as an unhandled Win32 exception/JIT debug dialog while DesktopScroll was running. The failure mode is consistent with an exception escaping the low-level keyboard hook callback boundary.

  • Root-cause containment

    • Wrapped GlobalKeyboardHookService.HookCallback(...) in a defensive try/catch so managed exceptions do not cross the Win32 hook boundary and terminate the process.
  • Hook-chain safety

    • On callback failure, the handler now logs and still returns CallNextHookEx(...), preserving hook-chain behavior instead of crashing the app.
  • Diagnostics quality

    • Updated error logging to capture the full exception payload (ex.ToString() via interpolation) for actionable postmortem detail.
private IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
    try
    {
        // existing key processing / handled path
    }
    catch (Exception ex)
    {
        RuntimeTrace.Write($"Global keyboard hook callback error: {ex}");
    }

    return CallNextHookEx(_hookHandle, nCode, wParam, lParam);
}

Copilot AI linked an issue Sep 1, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix frequent app crashes during use Prevent process crashes from unhandled exceptions in global keyboard hook callback Sep 1, 2026
Copilot AI requested a review from 0RuiAlvel0 September 1, 2026 02:06
@0RuiAlvel0

Copy link
Copy Markdown
Owner

no changes made. I implemented the recommendation myself.

@0RuiAlvel0 0RuiAlvel0 closed this Sep 1, 2026
@0RuiAlvel0 0RuiAlvel0 mentioned this pull request Sep 1, 2026
@0RuiAlvel0
0RuiAlvel0 deleted the copilot/fix-frequent-app-crashes branch September 11, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Frequent app crashes

2 participants