bevyengine / bevy

A refreshingly simple data-driven game engine built in Rust
https://bevyengine.org
Apache License 2.0
35.93k stars 3.55k forks source link

`Camera` bundle causes window resizing to crash #16116

Closed BenjaminBrienen closed 4 hours ago

BenjaminBrienen commented 5 hours ago

Bevy version

0.15-dev

What you did

Run relative_cursor_position example spawning the Camera2d with a Camera bundle.

    commands.spawn((
        Camera2d,
        Camera {
            // Cursor position will take the viewport offset into account
            viewport: Some(Viewport {
                physical_position: [200, 100].into(),
                physical_size: [600, 600].into(),
                ..default()
            }),
            ..default()
        },
    ));

What went wrong

Crashes as you see in #15661

Additional information

This is fixed by changing the bundle:

    commands.spawn((
        Camera2d,
        Transform::from_xyz(0., 0., 0.).looking_at(Vec3::ZERO, Vec3::Y),
    ));

It should be possible to spawn the Camera2d with a Camera bundle.

BenjaminBrienen commented 4 hours ago

The solution is to add a system set_camera_viewports which handles dynamic resizing.