fix: prevent stale Focused(false) events from clearing valid focus and freezing rendering#8231
Open
rustbasic wants to merge 7 commits into
Open
fix: prevent stale Focused(false) events from clearing valid focus and freezing rendering#8231rustbasic wants to merge 7 commits into
Focused(false) events from clearing valid focus and freezing rendering#8231rustbasic wants to merge 7 commits into
Conversation
Refactor focused viewport handling to prevent stale focus events.
|
Preview available at https://egui-pr-preview.github.io/pr/8231-p103 View snapshot changes at kitdiff |
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.
fix: prevent stale
Focused(false)events from clearing valid focus and freezing renderingWindows#5063Description
This PR fixes a rare and elusive screen-freezing issue in
egui(especially noticeable on Windows 10/11) where the UI rendering permanently stops after running the application for a prolonged period (e.g., once or twice a day during all-day usage).Cause of the Issue
Previously, any
WindowEvent::Focused(false)event would unconditionally resetfocused_viewporttoNone. In multi-window environments or when Windows OS dispatches stale/out-of-order focus events, a staleFocused(false)event from another window/viewport would clear the currently active viewport's focus state.Once the focus state was incorrectly cleared or desynchronized, the application would stop repainting under certain conditions, causing the screen to freeze while the background logic continued running responsiveness-free.
Solution
Only clear
shared.focused_viewportif the viewport losing focus actually matches the one we currently believe to be focused:Explicitly set
repaint_asap = trueon anyFocusedevent to ensure the UI updates immediately and stays responsive when focus transitions occur.Since this bug occurs semi-randomly over long sessions and is highly dependent on OS-level window focus dispatching, it is extremely difficult to write a minimal reproducible example. However, guarding the state transition and forcing a repaint completely resolves the long-term freeze issue.