Skip to content

DirectX12 Window resize fails after deactivating camera #25740

Description

@tGitzHub

Bevy version and features

0.19.1 b56fc29d3016e641754765244b5ba3f9cc504671
and master 7a21c21ecbce9ba28c970ffdf73063321b6bb636

Relevant system information

DX12

AdapterInfo { name: "AMD Radeon RX 9060 XT", vendor: 4098, device: 30096, device_type: DiscreteGpu, device_pci_bus_id: "0000:0c:00.0", driver: "32.0.31041.1004", driver_info: "", backend: Dx12, subgroup_min_size: 32, subgroup_max_size: 64, transient_saves_memory: Some(false), limit_bucket: None }

Vulkan

AdapterInfo { name: "AMD Radeon RX 9060 XT", vendor: 4098, device: 30096, device_type: DiscreteGpu, device_pci_bus_id: "", driver: "AMD proprietary driver", driver_info: "26.8.1 (LLPC)", backend: Vulkan, subgroup_min_size: 32, subgroup_max_size: 64, transient_saves_memory: Some(false), limit_bucket: None }

What you did

I was playing around with handing over from one camera to the next in a pet project of mine. Things run fine on metal (M5 Pro) and Vulkan (9060 XT 16GB) but kept crashing on DX12:

  • Created 2 3D cameras; one active, one inactive,
  • swap after some frames, keeping the inactive alive
  • resize window

What went wrong

DX12 exits with exit code 1, while Vulkan works fine
DX12 reports via DebugView:
DXGI ERROR: IDXGISwapChain::ResizeBuffers: Swapchain cannot be resized unless all outstanding buffer references have been released. [ MISCELLANEOUS ERROR #19: ]

See minimal runner attached. Uses DX12 by default and Vulkan via --vulkan flag.
Place this into examples/ and run
cargo run --example camera_resize_script (for DX12)
cargo run --example camera_resize_script -- --vulkan (for Vulkan)

Minimal runner: camera_resize_script.rs
use bevy::{
    prelude::*,
    render::{settings::*, RenderPlugin},
};

fn main() -> AppExit {
    let backend = if std::env::args().any(|arg| arg == "--vulkan") {
        Backends::VULKAN
    } else {
        Backends::DX12
    };
    App::new()
        .add_plugins(DefaultPlugins.set(RenderPlugin {
            render_creation: RenderCreation::Automatic(Box::new(WgpuSettings {
                backends: Some(backend),
                ..default()
            })),
            ..default()
        }))
        .add_systems(Startup, |mut commands: Commands| {
            commands.spawn(Camera3d::default());
            commands.spawn((
                Camera3d::default(),
                Camera {
                    is_active: false,
                    ..default()
                },
            ));
        })
        .add_systems(Update, reproduce)
        .run()
}

fn reproduce(
    mut frame: Local<u32>,
    mut cameras: Query<&mut Camera>,
    mut window: Single<&mut Window>,
    mut exit: MessageWriter<AppExit>,
) {
    *frame += 1;
    match *frame {
        60 => {
            println!("Switching cameras, keeping the inactive camera alive");
            for mut camera in &mut cameras {
                camera.is_active = !camera.is_active;
            }
        }
        120 => {
            println!("Resizing window");
            window.resolution.set_physical_resolution(800, 450);
        }
        180 => {
            println!("Reached frame 180 without exiting on a render error");
            exit.write(AppExit::Success);
        }
        _ => {}
    }
}

Additional information

I managed to locally "fix" this by simply including ViewTarget in the fn extract_cameras in crates/bevy_render/src/camera.rs.
Thats just something an LLM suggested for me, maybe its still a good starting point for the investigation?

Also I dont think any other issue brings this up yet, but these seem related?:


Im very new to bevy, this is my first issue, i hope im doing this somewhat right :)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-BugAn unexpected or incorrect behaviorS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions