bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Bevy segfaults when using wayland

Open InnocentusLime opened this issue 3 years ago • 9 comments

Bevy version

Bevy 0.8.1

[Optional] Relevant system information

OS: Ubuntu 22.04.1 LTS, Wayland. The app is run natively

Adapter info printed by bevy:

2022-09-13T14:08:53.880285Z  INFO bevy_render::renderer: AdapterInfo { name: "Intel(R) HD Graphics 620 (KBL GT2)", vendor: 32902, device: 22806, device_type: IntegratedGpu, backend: Vulkan }

What you did

Create the following project:

// main.rs
use bevy::prelude::*;

fn main() {
  App::new().add_plugins(DefaultPlugins).update();
}
#Cargo.toml
[package]
name = "bevy_crash"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = { version = "0.8", features = ["wayland"] }

And then cargo run it.

What went wrong

The app was supposed to show a window, close it and exit. Instead of that, a segmentation fault occurs.

Additional information

I have run the program with gdb connected and managed to get a backtrace:

#0  0x00007ffff7b1f85a in ?? () from /lib/x86_64-linux-gnu/libwayland-client.so
#1  0x00007ffff7b211bb in wl_proxy_marshal_array_flags () from /lib/x86_64-linux-gnu/libwayland-client.so
#2  0x00007ffff7b21caf in wl_proxy_marshal_flags () from /lib/x86_64-linux-gnu/libwayland-client.so
#3  0x00007fffd937038c in ?? () from /usr/lib/x86_64-linux-gnu/libvulkan_intel.so
#4  0x00007fffd9370536 in ?? () from /usr/lib/x86_64-linux-gnu/libvulkan_intel.so
#5  0x000055555750959d in ash::extensions::khr::swapchain::Swapchain::destroy_swapchain (self=0x7ffffffeb7e0, swapchain=..., allocation_callbacks=...)
    at src/extensions/khr/swapchain.rs:29
#6  0x00005555573d0353 in wgpu_hal::vulkan::instance::{impl#5}::unconfigure (self=0x555559012970, device=0x5555592aab68) at src/vulkan/instance.rs:746
#7  0x0000555556ee7671 in wgpu_core::hub::Hub<wgpu_hal::vulkan::Api, wgpu_core::hub::IdentityManagerFactory>::clear<wgpu_hal::vulkan::Api, wgpu_core::hub::IdentityManagerFactory> (self=0x555559018538, surface_guard=0x555559018508, with_adapters=true)
    at /home/innocentus/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.13.2/src/hub.rs:822
#8  0x0000555556edad33 in wgpu_core::hub::{impl#72}::drop<wgpu_core::hub::IdentityManagerFactory> (self=0x555559018430)
    at /home/innocentus/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.13.2/src/hub.rs:1024
#9  0x00005555571e5907 in core::ptr::drop_in_place<wgpu_core::hub::Global<wgpu_core::hub::IdentityManagerFactory>> ()
<...a bunch of nested drop_in_place calls...>
#49 0x0000555557e07ff9 in core::ptr::drop_in_place<bevy_app::app::App> () at /rustc/4b91a6ea7258a947e59c6522cd5898e7c0a6a88f/library/core/src/ptr/mod.rs:487
#50 0x00005555559fd334 in bevy_crash_app::main () at src/main.rs:4

~~I have no idea what's causing this, I suppose that 0.26.1 does something 0.26.0 didn't do before (or contains a bug of some sort). the segfault happens if you add winit 0.26.0 as a dependency too~~

InnocentusLime avatar Sep 13 '22 10:09 InnocentusLime

I'm guessing winit is crashing because you have two versions of it since Bevy depends on 0.26.0 specifically.

tim-blackbird avatar Sep 13 '22 10:09 tim-blackbird

@devil-ira Cargo will unify both versions into 0.26.1. In fact of you try to depend on two different semver conpatible versions using = to pin a specific version, cargo will throw an error.

bjorn3 avatar Sep 13 '22 11:09 bjorn3

@devil-ira Cargo will unify both versions into 0.26.1. In fact of you try to depend on two different semver conpatible versions using = to pin a specific version, cargo will throw an error.

That's indeed what happened. The situation came to existence, because I tried updating my dependencies to the latest versions (well, to the latest versions cargo would allow me to) and for some reason bevy doesn't feel well when the patch version is incremented

InnocentusLime avatar Sep 13 '22 11:09 InnocentusLime

Right. That gets me every time. Don't mind me.

tim-blackbird avatar Sep 13 '22 12:09 tim-blackbird

I suspect that you would see a similar crash with

[dependencies]
bevy = { "0.8", features = ["wayland"] }

Your own winit dep is dragging in that feature which bevy doesn't include by default.

rparrett avatar Sep 13 '22 13:09 rparrett

I suspect that you would see a similar crash with

[dependencies]
bevy = { "0.8", features = ["wayland"] }

Your own winit dep is dragging in that feature which bevy doesn't include by default.

Yup! I have just tested this. Simply asking for wayland makes it segfault too. I will update the example

InnocentusLime avatar Sep 13 '22 14:09 InnocentusLime

Please also include the AdapterInfo output from bevy (when it is not crashing). It looks like you might be on an intel GPU?

rparrett avatar Sep 13 '22 14:09 rparrett

Please also include the AdapterInfo output from bevy (when it is not crashing). It looks like you might be on an intel GPU?

I indeed am. Including the adapter info into the report

InnocentusLime avatar Sep 13 '22 14:09 InnocentusLime

0.8.1 + Wayland works here on a Raptor Lake booted into Ubuntu 22.10. Though I am manually depending on winit. Perhaps try adding something like the following and see if it works.

[dependencies.winit]
version = "0.26.0"
features = []
optional = false
default-features = false

AxiomaticSemantics avatar Nov 12 '22 06:11 AxiomaticSemantics

@InnocentusLime is this resolved now?

AxiomaticSemantics avatar Jan 06 '23 05:01 AxiomaticSemantics

@InnocentusLime is this resolved now?

@AxiomaticSemantics Have just downloaded bevy 0.9 on that same laptop after downloading last updates for the same OS (Ubuntu). The SEGFAULT is still happening.

InnocentusLime avatar Jan 06 '23 14:01 InnocentusLime

Still unresolved damn happens on 0.10.1 too

Tofixrs avatar May 25 '23 15:05 Tofixrs

I found with the same case:

// main.rs
use bevy::prelude::*;

fn main() {
  App::new().add_plugins(DefaultPlugins).update();
}

With package config like

#Cargo.toml
[package]
name = "bevy_crash"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = {version = "0.10.1", features = ["x11"]}

Or not specify any Bevy features:

#Cargo.toml
[package]
name = "bevy_crash"
version = "0.1.0"
edition = "2021"

[dependencies]
bevy = "0.10.1"

The app will also has a segment fault:

Finished dev [unoptimized + debuginfo] target(s) in 6.10s
     Running `/home/vitalyr/projects/dev/rust-projects/rust_play/target/debug/bevy_test`
2023-05-31T02:48:45.333538Z  INFO bevy_winit::system: Creating new window "Bevy App" (0v0)
2023-05-31T02:48:45.333787Z  INFO winit::platform_impl::platform::x11::window: Guessed window scale factor: 2    
2023-05-31T02:48:45.591677Z  INFO bevy_render::renderer: AdapterInfo { name: "NVIDIA GeForce RTX 3060 Laptop GPU", vendor: 4318, device: 9568, device_type: DiscreteGpu, driver: "NVIDIA", driver_info: "530.41.03", backend: Vulkan }
2023-05-31T02:48:46.109752Z  INFO bevy_diagnostic::system_information_diagnostics_plugin::internal: SystemInfo { os: "Linux  Arch Linux", kernel: "6.3.5-zen1-1-zen", cpu: "12th Gen Intel(R) Core(TM) i7-12700H", core_count: "14", memory: "31.1 GiB" }
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/vitalyr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_render-0.10.1/src/pipelined_rendering.rs:135:84
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', /home/vitalyr/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_tasks-0.10.1/src/task_pool.rs:376:49
thread '<unnamed>' panicked at 'cannot access a Thread Local Storage value during or after destruction: AccessError', /rustc/498553fc04f6a3fdc53412320f4e913bc53bc267/library/std/src/thread/local.rs:246:26
fatal runtime error: failed to initiate panic, error 5
Aborted: oops, process 'cargo' core dumped

After changing App::new().add_plugins(DefaultPlugins).update(); to App::new().add_plugins(DefaultPlugins).run();, it runs well. This problem seems not related to Wayland or X11. It's a problem that Bevy can't run code like App::new().add_plugins(DefaultPlugins).update();. And indeed it's rare to write code like this.

VitalyAnkh avatar May 31 '23 03:05 VitalyAnkh

@VitalyAnkh im pretty sure u were using xwayland to run the game To enable native wayland support you need to add the waylandd feature wich then makes it segfault for me with App::new().add_plugins(DefaultPlugins).run()

Tofixrs avatar Jun 02 '23 11:06 Tofixrs

@Tofixrs No, it doesn't segfault when enabling Bevy's wayland feature with App::new().add_plugins(DefaultPlugins).run(). Please watch my screen recording: 录屏 2023-06-02 20-08-10.webm

VitalyAnkh avatar Jun 02 '23 12:06 VitalyAnkh

@VitalyAnkh guess its something with my system then. Sorry for the false report

Tofixrs avatar Jun 02 '23 12:06 Tofixrs

I got same problem, does someone know how to fix it? @Tofixrs did you fix it? Ubuntu 22 wayland

GodGotzi avatar Oct 11 '23 22:10 GodGotzi