bevyengine / bevyengine/bevy

Window size isn't correct until second frame when scale factor is overridden

Open
#17,188 5 comments 0 reactions 0 assignees View on GitHub
A-Windowing C-Bug D-Straightforward S-Needs-Investigation
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

main

## Relevant system information

SystemInfo { os: "macOS 14.5 Sonoma", kernel: "23.5.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }
AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

High DPI display (scale factor 2)

## What you did

```rust
use bevy::{diagnostic::FrameCount, prelude::*, window::WindowResolution};

fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: WindowResolution::new(1920.0, 1080.0).with_scale_factor_override(1.0),
..default()
}),
..default()
}))
.add_systems(Startup, startup)
.add_systems(Update, print_windows)
.run();
}

fn startup(windows: Query<&Window>, frame_count: Res) {
for window in &windows {
info!("{} {:?} (startup)", frame_count.0, window.resolution);
}
}

fn print_windows(windows: Query<&Window>, frame_count: Res) {
for window in &windows {
info!("{} {:?} (update)", frame_count.0, window.resolution);
}
}
```

## What went wrong

The `WindowResolution` is incorrect during `Startup` and for one run of the `Update` schedule, and then becomes correct on the next frame.

```
2025-01-06T12:55:54.906932Z INFO bevy_winit::system: Creating new window App (0v1)
2025-01-06T12:55:54.932602Z INFO sfo: Frame 0: WindowResolution { physical_width: 3840, physical_height: 2160, scale_factor_override: Some(1.0), scale_factor: 2.0 } (startup)
2025-01-06T12:55:54.941606Z INFO sfo: Frame 0: WindowResolution { physical_width: 3840, physical_height: 2160, scale_factor_override: Some(1.0), scale_factor: 2.0 } (update)
2025-01-06T12:55:55.002012Z INFO sfo: Frame 1: WindowResolution { physical_width: 1920, physical_height: 1080, scale_factor_override: Some(1.0), scale_factor: 2.0 } (update)
```

## Additional information

Related to #17183

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.