bevyengine / bevy

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

Crash due to DefaultPlugins adding before adding Msaa and WindowDescriptor (??) #1174

Closed Adevald closed 1 year ago

Adevald commented 3 years ago

Bevy version

bevy = { version = "0.4.0" }

Operating system & version

Windows 10 x64.

What you did

Using this tutorial for creating an chess prototype, i insert .add_plugins(DefaultPlugins) right after App::build() (tutorial tell it should be after .add_resource(WindowDescriptor{}) ).

What you expected to happen

App just should works.

What actually happened

App crashed with error: thread 'main' panicked at 'render pipeline output formats and sample counts do not match render pass attachment formats

Additional information

That error doesnt appear if DefaultPlugins will placed after .add_resource(WindowDescriptor{}).

Also, WindowDescriptor{} doesnt appies to App if it added after DefaultPlugins.

Code:

fn main() {
    App::build()
        .add_plugins(DefaultPlugins)
        .add_resource(Msaa {samples: 4})
        .add_resource(WindowDescriptor {
            title: "Chess Tutorial".to_string(),
            width: 1024.0,
            height: 780.0,
            ..Default::default()
        })
        .add_startup_system(setup.system())
        .run();
}

fn setup(
    commands: &mut Commands,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
 // full copy of tutorial code 
}
Roba1993 commented 3 years ago

You First need to add the resources and then the plugin. I don’t know why, but it should solve the problem.

Can this be changed or described somewhere?

Adevald commented 3 years ago

You First need to add the resources and then the plugin. I don’t know why, but it should solve the problem.

Can this be changed or described somewhere?

I know this and i tell about it here

that error doesnt appear if DefaultPlugins will placed after .add_resource(WindowDescriptor{})

cart commented 3 years ago

Yup the issue is that we initialize the RenderGraph in the RenderPlugin using the Msaa resource settings. We then separately configure shader pipeline specialization using the Msaa resource setting.

If you register Msaa before DefaultPlugins (which includes RenderPlugin), the graph gets initialized with the custom value AND the shader pipelines get specialized with the custom value.

If you register Msaa after, the RenderGraph gets initialized with the default Msaa value, but the shader pipelines get specialized with the custom value.

I believe the fix should be to allow the RenderGraph to dynamically adapt to Msaa resource settings. But that will require some design work.

Another fix might be to defer Plugin initialization until app start, which would ensure that resources are always registered before plugins (but im not yet convinced that behavior is desirable).

arekbal commented 3 years ago

I would expect of builder pattern to gather the settings before starting the actual process of "building".

mockersf commented 1 year ago

this no longer crashes: