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

When VIEWPORT is set to CAMERA and switched to SizedFullscreen, PANIC may occur. #12000

Closed
hyoi opened this issue Feb 20, 2024 · 2 comments · Fixed by #12861
Closed

When VIEWPORT is set to CAMERA and switched to SizedFullscreen, PANIC may occur. #12000

hyoi opened this issue Feb 20, 2024 · 2 comments · Fixed by #12861
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior P-Crash A sudden unexpected crash S-Needs-Investigation This issue requires detective work to figure out what's going wrong

Comments

@hyoi
Copy link

hyoi commented Feb 20, 2024

Bevy version

v0.13.0, 0.13.1

Relevant system information

2024-02-20T12:45:02.631105Z  INFO bevy_render::renderer: AdapterInfo { name: "Intel(R) Iris(R) Xe Graphics", vendor: 32902, device: 18086, device_type: IntegratedGpu, driver: "Intel Corporation", driver_info: "Intel driver", backend: Vulkan }
2024-02-20T12:45:04.399604Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Windows 11 Home", kernel: "22621", cpu: "12th Gen Intel(R) Core(TM) i7-1260P", core_count: "12", memory: "31.7 GiB" }
2024-02-20T12:45:09.668606Z ERROR log: Handling wgpu errors as fatal by default    
thread '<unnamed>' panicked at C:\Users\hyoi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wgpu-0.19.1\src\backend\wgpu_core.rs:3009:5:
wgpu error: Validation Error

Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 181, Vulkan)>`     
    In a set_viewport command
    Viewport has invalid rect Rect { x: 0.0, y: 0.0, w: 1376.0, h: 768.0 }; origin and/or size is less than or equal to 0, and/or is not contained in the render target (1366, 768, 1) 


note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Encountered a panic in exclusive system `bevy_render::renderer::render_system`!
thread 'Compute Task Pool (1)' panicked at C:\Users\hyoi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\bevy_render-0.13.0\src\pipelined_rendering.rs:49:67:
called `Result::unwrap()` on an `Err` value: RecvError       
error: process didn't exit successfully: `target\release\work.exe` (exit code: 101)

What you did

On my PC, I can reproduce PANIC with the following program.
This program first displays an empty window, and then the [SPACE] key toggles between Windowed and SizedFullscreen display.
PANIC occurs when WINDOW_WIDTH is 1376.0, and there is no problem when WINDOW_WIDTH is 1366.0.

use bevy::
{   prelude::*,
    render::camera::Viewport,
    window::WindowMode,
};

// const WINDOW_WIDTH : f32 = 1366.0; //No problem
const WINDOW_WIDTH : f32 = 1376.0; //Panic: Viewport has invalid rect
const WINDOW_HEIGHT: f32 = 768.0;

fn main()
{   //Specify Window Size.
    let window = Window { resolution: ( WINDOW_WIDTH, WINDOW_HEIGHT ).into(), ..default() };
    let primary_window = Some ( window );

    App::new()
        .add_plugins( DefaultPlugins.set( WindowPlugin { primary_window, ..default() } ) )
        .add_systems( Startup, startup )
        .add_systems( Update, toggle_window_mode )
        .run();
}

fn startup( mut cmds: Commands )
{   //Match viewport to Window size.
    let physical_position = UVec2::new( 0, 0 );
    let physical_size = Vec2::new( WINDOW_WIDTH, WINDOW_HEIGHT ).as_uvec2();
    let viewport = Some ( Viewport { physical_position, physical_size, ..default() } );

    cmds.spawn( Camera2dBundle::default() ).insert( Camera { viewport, ..default() } );
}

fn toggle_window_mode
(   mut qry_window: Query<&mut Window>,
    inkey: Res<ButtonInput<KeyCode>>,
)
{   let Ok( mut window ) = qry_window.get_single_mut() else { return };

    //Press [SPACE] key to toggle between window and full screen.
    if inkey.just_pressed( KeyCode::Space )
    {   window.mode = match window.mode
        {   WindowMode::Windowed => WindowMode::SizedFullscreen,
            _                    => WindowMode::Windowed,
        };
    }
}

What went wrong

  • VIEWPORT validation has been added to WGPU V0.18.0. #4058
  • I thought that if the resolution after SizedFullscreen setting is lower than the original window resolution, the VIEWPORT would result in a validation error and PANIC.
@hyoi hyoi added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Feb 20, 2024
@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen P-Crash A sudden unexpected crash S-Needs-Investigation This issue requires detective work to figure out what's going wrong and removed S-Needs-Triage This issue needs to be labelled labels Feb 20, 2024
@hyoi
Copy link
Author

hyoi commented Mar 20, 2024

Checked for panic in v0.13.1.

LuisFigueiredo73 added a commit to LuisFigueiredo73/bevy that referenced this issue Mar 30, 2024
…o SizedFullscreen, Panic may occur

When Viewport is set to Some when adding a Camera, panic occured because while adjusting to SizedFullscreen,
the operating system may return a lower size for the window, resulting in panic because the Viewport is
bigger than the render target. The fix consist of, if the size is in fact lower than the Viewport size,
the Viewport's physical size is updated to the smaller value, avoiding panic. The values returned by the
operating system may vary, depending on the device (the values that the person that opened the issue gave
for panic occuring were not the same as the ones that caused panic for me).
@hyoi
Copy link
Author

hyoi commented Mar 31, 2024

I changed [dependencies] in Cargo.toml as follows and compiled it, and now the trouble does not occur on my PC. Thank you very much, LuisFigueiredo73 .

[dependencies]
bevy = { git = "https://github.com/LuisFigueiredo73/bevy", branch = "Viewport_panic" }
#bevy = "0.13.1"

LuisFigueiredo73 added a commit to LuisFigueiredo73/bevy that referenced this issue Apr 1, 2024
…o SizedFullscreen, panic may occur

When ajusting to SizedFullscreen, the window size might be lower than the viewport size, causing the render
target to be smaller than the Viewport. The fix consist of matching the viewport size with the render target
size when this is lower, avoiding panic. These lower values may vary depending on the device.
LuisFigueiredo73 added a commit to LuisFigueiredo73/bevy that referenced this issue Apr 3, 2024
…o SizedFullscreen, panic may occur

When viewport is set to the same size as the window on creation, when adjusting to SizedFullscreen,
the window may be smaller than the viewport for a moment, which caused the arguments to be invalid.
The fix consists of matching the size of the viewport to the size of the window when it is smaller.
Also added a test to show that it does not panic.
github-merge-queue bot pushed a commit that referenced this issue Apr 6, 2024
#12861)

# Objective

- When viewport is set to the same size as the window on creation, when
adjusting to SizedFullscreen, the window may be smaller than the
viewport for a moment, which caused the arguments to be invalid and
panic.
- Fixes #12000.

## Solution

- The fix consists of matching the size of the viewport to the lower
size of the window ( if the x value of the window is lower, I update
only the x value of the viewport, same for the y value). Also added a
test to show that it does not panic anymore.

---
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 C-Bug An unexpected or incorrect behavior P-Crash A sudden unexpected crash S-Needs-Investigation This issue requires detective work to figure out what's going wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants