bevyengine / bevy

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

Regression: Disabling `multi_threaded` feature causes broken rendering #14993

Closed BigWingBeat closed 3 months ago

BigWingBeat commented 3 months ago

Bevy version

[Optional] Relevant system information

What you did

[dependencies] bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", default-features = false, features = [ "x11", "bevy_core_pipeline", ] }


- main.rs:
```rust
use bevy::prelude::*;

fn main() -> AppExit {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_systems(Startup, |world: &mut World| {
            world.spawn(Camera3dBundle::default()); // Camera2dBundle also works
        })
        .run()
}

What went wrong

1

3

Additional information

Changing the above Cargo.toml to the following fixes the issue:

[package]
name = "testy"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = { git = "https://github.com/bevyengine/bevy", branch = "main", default-features = false, features = [
    "x11",
    "bevy_core_pipeline",
+   "multi_threaded",
] }

Additionally, all other features seem to have no effect on it. You can manually re-enable all of the default features except multi_threaded, and the issue still occurs. Then enable multi_threaded, and it's fixed.

alice-i-cecile commented 3 months ago

Thanks for the report! The next step is to bisect the git history to try and figure out which commit is responsible.

BigWingBeat commented 3 months ago

Git bisect says d9527c101c2f49c6884763cce36ea1d27dd6a597 is the first bad commit, which is #14833.

alice-i-cecile commented 3 months ago

Fantastic. FYI @tychedelia <3

tychedelia commented 3 months ago

Whoa, huh, will look into this.

tychedelia commented 3 months ago

Cannot reproduce on Windows with:

AdapterInfo { name: "NVIDIA GeForce RTX 4090", vendor: 4318, device: 9860, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "546.12", backend: Vulkan }

But I have an idea and will continue to dig.

JMS55 commented 3 months ago

Broken rendering like this should never happen. Sounds like wgpu messed up the synchronization somewhere.

tychedelia commented 3 months ago

@BigWingBeat Are you seeing this behavior in a more non-minimal repro? One thing I'm confused about is that on Windows and macOS, a window doesn't even open with this configuration. It seems like the x11 feature is causing a window to be created which maybe is an unrelated bug, but just want to confirm that you are seeing issues outside of the repro.

BigWingBeat commented 3 months ago

@BigWingBeat Are you seeing this behavior in a more non-minimal repro? One thing I'm confused about is that on Windows and macOS, a window doesn't even open with this configuration. It seems like the x11 feature is causing a window to be created which maybe is an unrelated bug, but just want to confirm that you are seeing issues outside of the repro.

Yes, broadly speaking it seems like the issue occurs with any bevy project that has an open window, a spawned camera, and multi_threaded disabled. This includes most of Bevy's built-in examples, as long as you also re-enable whatever other features the examples need.

You should be able to just enable the bevy_winit feature which I assume is what makes a window open. Also note that sometimes you need to re-run the app several times before the visual artifacts start appearing, although sometimes they appear immediately.

tychedelia commented 3 months ago

@BigWingBeat will you cherry-pick the fix from https://github.com/bevyengine/bevy/pull/15000 and see if that fixes things for you?

BigWingBeat commented 3 months ago

@BigWingBeat will you cherry-pick the fix from #15000 and see if that fixes things for you?

Yeah, that fixed it!