Skip to content

Conversation

@MarijnS95
Copy link
Contributor

@MarijnS95 MarijnS95 commented Dec 8, 2025

We found in our application (with custom egui renderer) that the screen_rect in RawInput was mismatching with the winit events that we processed earlier (in particular on resize on MacOS, which raises a lot of small size changes).

One of the contributing factors was egui-winit reading the Window size and scale factor over and over again separate from processed events, causing a mismatch on some platforms because this value would already change ahead of consuming a Resized event. Secondly, some existing event processing may rely on this value being consistent with the event stream.

There is currently no guarantee -at least I don't see it in the documentation- that winit ensures that inner_size() will always return a consistent value until the user has consumed a Resized event. This gets worse when certain functions (like update_viewport_info()) are possibly called on a separate thread because both egui::Context and winit::Window are thread-safe.

Those also have an extra draw-back of roundtripping to the event loop on the main thread to query these values, as a Window is not actually thread-safe on all platforms.

  • I have followed the instructions in the PR template

This is still opened as a draft because it has not been tested on all platforms, and there are far more odd calls to window.inner_size(), window.outer_size() and window.scale_factor() than anticipated which might all suffer from the same behaviour; not all immediately have access to the latest state in RawInput though.

Secondly it was surprising to see the viewport code that updates native_pixels_per_point in a very disconnected way from RawInput::pixels_per_point, which I'd like to understand better before making any more changes here. It seems like this was already all carefully crafted (ie. #4211) and battle-tested to circumnavigate the inconsistency issues above... 😕

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

Preview available at https://egui-pr-preview.github.io/pr/7760-winit-fix-window-size-inconsistency
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

@MarijnS95 MarijnS95 force-pushed the winit-fix-window-size-inconsistency branch from 1676c48 to 402e239 Compare December 8, 2025 12:56
.get(&self.viewport_id)
.expect("No viewport")
.native_pixels_per_point
.expect("ScaleFactorChanged must have been raised")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the pure_glow example on Wayland we seem to receive Resized -> RedrawRequested -> ScaleFactorChanged.

This'll panic because they're out of order, and we might need to make sure to update the input size again also when the scale factor changes.

We found in our application (with custom `egui` renderer) that the
`screen_rect` in `RawInput` was mismatching with the `winit` events that
we processed earlier (in particular on resize on MacOS, which raises a
lot of small size changes).

One of the contributing factors was `egui-winit` reading the `Window`
size and scale factor over and over again separate from processed
events, causing a mismatch on some platforms because this value would
already change ahead of consuming a `Resized` event.  Secondly, some
existing event processing may rely on this value being consistent with
the event stream.

There is currently no guarantee -at least I don't see it in the
documentation- that `winit` ensures that `inner_size()` will always
return a consistent value until the user has consumed a `Resized` event.
This gets worse when certain functions (like `update_viewport_info()`)
are possibly called on a separate thread because both `egui::Context`
and `winit::Window` are thread-safe.

Those also have an extra draw-back of roundtripping to the event loop
on the main thread to query these values, as a `Window` is not actually
thread-safe on all platforms.
@MarijnS95 MarijnS95 force-pushed the winit-fix-window-size-inconsistency branch from 402e239 to 8b30dde Compare December 8, 2025 14:25
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.

1 participant