Fix KeyboardToolTipStateMachine KeyNotFoundException when focus changes during tooltip popup event#14731
Open
LeafShi1 wants to merge 1 commit into
Open
Fix KeyboardToolTipStateMachine KeyNotFoundException when focus changes during tooltip popup event#14731LeafShi1 wants to merge 1 commit into
LeafShi1 wants to merge 1 commit into
Conversation
…es during tooltip popup event
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes crashes in WinForms keyboard ToolTip handling when focus changes re-entrantly during ToolTip.Popup, by making the KeyboardToolTipStateMachine more resilient to unexpected transitions and late timer callbacks.
Changes:
- Replace the “unknown transition” fallback from throwing
KeyNotFoundExceptionto performing a full FSM reset. - Add a guard in
Transit()to handle a nullsource(e.g., from late timer callbacks) and reset safely.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| bool fullFsmResetRequired = false; | ||
| try | ||
| { | ||
| if (source is null) |
Comment on lines
+76
to
+78
| // Reentrant focus changes can yield event/state combinations outside the normal transition table. | ||
| // Resetting avoids surfacing framework exceptions to application code. | ||
| (_, _) => FullFsmReset() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14729
Root Cause
Calling
Focus()in ToolTip.Popup event causes re-entrant focus change that creates invalid state-event combinations, triggeringKeyNotFoundException. Timer callbacks on unhooked tools causeArgumentNullException.Proposed changes
KeyNotFoundException()withFullFsmReset()Transit()method before accessing weak reference tableCustomer Impact
Regression?
Risk
Screenshots
Before
Switching focus to the second text box using the Tab key triggers an /ArgumentNullException pop-up.
in .NET framework 4.8.1:
in .net10 application:
After
App continues running
AfterChanges.mp4
Test methodology
Test environment(s)
Microsoft Reviewers: Open in CodeFlow