Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale factor override crossing screens with different native scale factors causes odd behaviour #2751

Closed
DJMcNab opened this issue Aug 30, 2021 · 0 comments
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior

Comments

@DJMcNab
Copy link
Member

DJMcNab commented Aug 30, 2021

Bevy version

c5717b5

Operating system & version

Windows 10

What you did

Created a program which locks the window size, includes two sprites and:

Code
use bevy::prelude::*;

const WIDTH: f32 = 600.;
const HEIGHT: f32 = 200.;

fn main() {
    App::new()
        .insert_resource(WindowDescriptor {
            width: WIDTH,
            height: HEIGHT,
            scale_factor_override: Some(2.),
            resizable: false,
            ..Default::default()
        })
        .add_plugins(DefaultPlugins)
        .add_startup_system(setup)
        .run();
}

fn setup(mut commands: Commands, mut materials: ResMut<Assets<ColorMaterial>>) {
    commands.spawn_bundle(OrthographicCameraBundle::new_2d());
    // Create the ground
    commands.spawn_bundle(SpriteBundle {
        material: materials.add(Color::BLUE.into()),
        sprite: Sprite::new(Vec2::new(WIDTH, 100.)),
        transform: Transform::from_xyz(0., (-HEIGHT + 15.) / 2., 0.),
        ..Default::default()
    });
    commands.spawn_bundle(SpriteBundle {
        material: materials.add(Color::YELLOW.into()),
        sprite: Sprite::new(Vec2::new(WIDTH, 15.)),
        transform: Transform::from_xyz(0., (-HEIGHT + 15.) / 2., 0.),
        ..Default::default()
    });
}

What you expected to happen

The same image should be rendered in the game window, no matter which monitor it is on. The window should have the size (1200, 400), since that is the window size times the scale factor:

image

What actually happened

When I move the game window from my primary monitor (which is a 4k screen with 125% scale factor) to my secondary screen (1080p, at 100% scale factor), the visible content changes to only show the blue sprite:

image

Additional information

This second version actually has a smaller window, which suggests that the bug is that something in this code

WindowEvent::ScaleFactorChanged {
scale_factor,
new_inner_size,
} => {
let mut backend_scale_factor_change_events = world
.get_resource_mut::<Events<WindowBackendScaleFactorChanged>>()
.unwrap();
backend_scale_factor_change_events.send(WindowBackendScaleFactorChanged {
id: window_id,
scale_factor,
});
#[allow(clippy::float_cmp)]
if window.scale_factor() != scale_factor {
let mut scale_factor_change_events = world
.get_resource_mut::<Events<WindowScaleFactorChanged>>()
.unwrap();
scale_factor_change_events.send(WindowScaleFactorChanged {
id: window_id,
scale_factor,
});
}
window.update_scale_factor_from_backend(scale_factor);
if window.physical_width() != new_inner_size.width
|| window.physical_height() != new_inner_size.height
{
let mut resize_events =
world.get_resource_mut::<Events<WindowResized>>().unwrap();
resize_events.send(WindowResized {
id: window_id,
width: window.width(),
height: window.height(),
});
}
window.update_actual_size_from_backend(
new_inner_size.width,
new_inner_size.height,
);
}

doesn't correctly handle a scale factor override properly (or at all).

CC @TheRawMeatball, who originally added this code in #1131

@DJMcNab DJMcNab added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in S-Needs-Triage This issue needs to be labelled labels Aug 30, 2021
@NiklasEi NiklasEi removed the S-Needs-Triage This issue needs to be labelled label Sep 5, 2021
DJMcNab added a commit to DJMcNab/bevy that referenced this issue Sep 7, 2021
@bors bors bot closed this as completed in 27bfbda Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants