bevyengine / bevy

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

Segmentation fault when running 2d_gizmos example #8144

Closed lewiszlw closed 1 year ago

lewiszlw commented 1 year ago

Bevy version

lastest main(caa662272ce).

[Optional] Relevant system information

AdapterInfo { name: "Apple M1", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }

SystemInfo { os: "MacOS 13.0 ", kernel: "22.1.0", cpu: "Apple M1", core_count: "8", memory: "16.0 GiB" }

What you did

cargo run --example 2d_gizmos

What went wrong

segmentation fault image

P.S. 3d_gizmos example works fine.

shuoli84 commented 1 year ago

Same here. It crashed with EXC_BAD_ACCESS

objc_release (@objc_release:7)
AutoreleasePoolPage::releaseUntil(objc_object**) (@AutoreleasePoolPage::releaseUntil(objc_object**):52)
objc_autoreleasePoolPop (@objc_autoreleasePoolPop:67)
<objc::rc::autorelease::AutoReleaseHelper as core::ops::drop::Drop>::drop (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/rc/autorelease.rs:17)
core::ptr::drop_in_place<objc::rc::autorelease::AutoReleaseHelper> (@core::ptr::drop_in_place<objc::rc::autorelease::AutoReleaseHelper>:9)
objc::rc::autorelease::autoreleasepool (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/objc-0.2.7/src/rc/autorelease.rs:30)
wgpu_hal::metal::device::<impl wgpu_hal::Device<wgpu_hal::metal::Api> for wgpu_hal::metal::Device>::create_render_pipeline (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-hal-0.15.3/src/metal/device.rs:807)
wgpu_core::device::Device<A>::create_render_pipeline (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.15.1/src/device/mod.rs:3030)
wgpu_core::device::<impl wgpu_core::hub::Global<G>>::device_create_render_pipeline (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-core-0.15.1/src/device/mod.rs:4938)
<wgpu::backend::direct::Context as wgpu::context::Context>::device_create_render_pipeline (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.15.1/src/backend/direct.rs:1174)
<T as wgpu::context::DynContext>::device_create_render_pipeline (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.15.1/src/context.rs:2191)
wgpu::Device::create_render_pipeline (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.15.1/src/lib.rs:2055)
bevy_render::renderer::render_device::RenderDevice::create_render_pipeline (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_render/src/renderer/render_device.rs:105)
bevy_render::render_resource::pipeline_cache::PipelineCache::process_render_pipeline (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_render/src/render_resource/pipeline_cache.rs:612)
bevy_render::render_resource::pipeline_cache::PipelineCache::process_queue (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_render/src/render_resource/pipeline_cache.rs:683)
bevy_render::render_resource::pipeline_cache::PipelineCache::process_pipeline_queue_system (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_render/src/render_resource/pipeline_cache.rs:718)
core::ops::function::FnMut::call_mut (@core::ops::function::FnMut::call_mut:14)
core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut (@core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut:19)
<Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0) .> Out>>::run::call_inner (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_ecs/src/system/function_system.rs:648)
<Func as bevy_ecs::system::function_system::SystemParamFunction<fn(F0) .> Out>>::run (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_ecs/src/system/function_system.rs:651)
<bevy_ecs::system::function_system::FunctionSystem<Marker,F> as bevy_ecs::system::system::System>::run_unsafe (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_ecs/src/system/function_system.rs:485)
bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor::spawn_system_task::{{closure}}::{{closure}} (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs:448)
core::ops::function::FnOnce::call_once (@core::ops::function::FnOnce::call_once:7)
<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (@<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once:13)
std::panicking::try::do_call (@std::panicking::try::do_call:40)
__rust_try (@__rust_try:11)
std::panicking::try (@std::panicking::try:30)
std::panic::catch_unwind (@std::panic::catch_unwind:13)
bevy_ecs::schedule::executor::multi_threaded::MultiThreadedExecutor::spawn_system_task::{{closure}} (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_ecs/src/schedule/executor/multi_threaded.rs:446)
async_executor::Executor::spawn::{{closure}} (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.5.0/src/lib.rs:139)
async_task::raw::RawTask<F,T,S>::run (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.3.0/src/raw.rs:511)
async_task::runnable::Runnable::run (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.3.0/src/runnable.rs:309)
async_executor::Executor::run::{{closure}}::{{closure}} (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.5.0/src/lib.rs:230)
<futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/future.rs:529)
async_executor::Executor::run::{{closure}} (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.5.0/src/lib.rs:237)
futures_lite::future::block_on::{{closure}} (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/future.rs:89)
std::thread::local::LocalKey<T>::try_with (@std::thread::local::LocalKey<T>::try_with:79)
std::thread::local::LocalKey<T>::with (@std::thread::local::LocalKey<T>::with:11)
futures_lite::future::block_on (/Users/shuoli/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/future.rs:79)
bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}::{{closure}}::{{closure}} (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_tasks/src/task_pool.rs:171)
std::panicking::try::do_call (@std::panicking::try::do_call:41)
__rust_try (@__rust_try:11)
std::panicking::try (@std::panicking::try:31)
std::panic::catch_unwind (@std::panic::catch_unwind:13)
bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}}::{{closure}} (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_tasks/src/task_pool.rs:165)
std::thread::local::LocalKey<T>::try_with (@std::thread::local::LocalKey<T>::try_with:91)
std::thread::local::LocalKey<T>::with (@std::thread::local::LocalKey<T>::with:16)
bevy_tasks::task_pool::TaskPool::new_internal::{{closure}}::{{closure}} (/Users/shuoli/.cargo/git/checkouts/bevy-f7ffde730c324c74/6a85eb3/crates/bevy_tasks/src/task_pool.rs:158)
std::sys_common::backtrace::__rust_begin_short_backtrace (@std::sys_common::backtrace::__rust_begin_short_backtrace:14)
std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}} (@std::thread::Builder::spawn_unchecked_::{{closure}}::{{closure}}:14)
<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once (@<core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once:14)
std::panicking::try::do_call (@std::panicking::try::do_call:48)
__rust_try (@__rust_try:11)
std::panicking::try (@std::panicking::try:37)
std::panic::catch_unwind (@std::panic::catch_unwind:14)
std::thread::Builder::spawn_unchecked_::{{closure}} (@std::thread::Builder::spawn_unchecked_::{{closure}}:101)
core::ops::function::FnOnce::call_once{{vtable.shim}} (@core::ops::function::FnOnce::call_once{{vtable.shim}}:9)
<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once (@std::sys::unix::thread::Thread::new::thread_start:15)
<alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once (@std::sys::unix::thread::Thread::new::thread_start:12)
std::sys::unix::thread::Thread::new::thread_start (@std::sys::unix::thread::Thread::new::thread_start:11)
_pthread_start (@_pthread_start:40)
shuoli84 commented 1 year ago

Should be introduced by pr #6529

irate-devil commented 1 year ago

@cwfitzgerald This seems to be coming from inside wgpu. Help would be appreciated if you have the time :)

cwfitzgerald commented 1 year ago

You can try running with METAL_WRAPPER_TYPE=1 in your env to see if there's a validation error, other than that, I'm lost.

lewiszlw commented 1 year ago

image

rparrett commented 1 year ago

The bloom_2d example also segfaults for me. Bisected to #6529.

AdapterInfo { name: "Apple M1 Max", vendor: 0, device: 0, device_type: IntegratedGpu, driver: "", driver_info: "", backend: Metal }
SystemInfo { os: "MacOS 13.1 ", kernel: "22.2.0", cpu: "Apple M1 Max", core_count: "10", memory: "64.0 GiB" }

Interestingly, bloom_2d (but not 2d_gizmos) also fails under in a CI environment

AdapterInfo { name: "llvmpipe (LLVM 15.0.6, 256 bits)", vendor: 65541, device: 0, device_type: Cpu, driver: "llvmpipe", driver_info: "Mesa 23.1.0-devel (git-270f9c0 2023-03-21 jammy-oibaf-ppa) (LLVM 15.0.6)", backend: Vulkan }
SystemInfo { os: "Linux 22.04 Ubuntu", kernel: "5.15.0-[103](https://github.com/rparrett/prototype_bevy_example_runner/actions/runs/4478769269/jobs/7871955336#step:10:104)4-azure", cpu: "Intel(R) Xeon(R) Platinum 8370C CPU @ 2.80GHz", core_count: "2", memory: "6.8 GiB" }
2023-03-21T12:24:15.705573Z ERROR wgpu::backend::direct: Handling wgpu errors as fatal by default    
thread '<unnamed>' panicked at 'wgpu error: Validation Error
Caused by:
    In a RenderPass
      note: encoder = `<CommandBuffer-(0, 1, Vulkan)>`
    In a set_pipeline command
      note: render pipeline = `gizmo_2d_pipeline`
    Render pipeline targets are incompatible with render pass
    Incompatible color attachment: the renderpass expected [Some(Rgba16Float)] but was given [Some(Rgba8UnormSrgb)]
cwfitzgerald commented 1 year ago

Sorry I gave the wrong env, it's METAL_DEVICE_WRAPPER_TYPE=1

irate-devil commented 1 year ago

Interestingly, bloom_2d (but not 2d_gizmos also fails under in a CI environment

Oops. I didn't specialize the 2d pipeline on HDR. I'll have a PR up shortly to fix that.

edit: #8151

rparrett commented 1 year ago

edit: #8151

Cool, seems like this was unrelated to the M1 segfaulting which is still happening in every example with a 2d camera as far as I can tell. (didn't test them all)

irate-devil commented 1 year ago

Cool, seems like this was unrelated to the M1 segfaulting

Yeah, I figured.

I don't see a reason why this happens as the 2d gizmo pipeline really doesn't do anything special and is mostly the same as the 3d one, except for not using a depth stencil and alpha blending being enabled.

Have you tried running it with METAL_DEVICE_WRAPPER_TYPE=1?

rparrett commented 1 year ago

Yeah, that emits a

2023-03-21 13:20:56.059 2d_gizmos[50337:22271848] Metal API Validation Enabled

message, but no validation errors.

doup commented 1 year ago

I'm getting this same issue when running ui examples, also concluded that https://github.com/bevyengine/bevy/pull/6529 was the origin.

JMS55 commented 1 year ago

I think issue this can now be closed.

EDIT: Nvm, I see there's another issue beside the HDR specialization.

irate-devil commented 1 year ago

I think this issue comes from upstream somewhere but it's a crash affecting enough users that it's worth trying to fix here. bevy_debug_lines uses almost the same rendering setup but does not have this issue so it should be possible

irate-devil commented 1 year ago

I have 2 ideas that might hopefully solve this.

  1. Maybe this issue is triggered by some particular combination of things. If this is the case then perhaps changing the shader setup slightly might randomly fix it. Please try the solid-gizmos branch on my fork which changes the shader/render pipeline slightly.
  2. Since bevy_debug_lines does not have this issue I tried to see what was different and the only thing I noticed was that it does not use LineStrip geometry. Please try the gizmos-no-strip branch to see if this is the problem. (If the 2d_gizmos example runs you should only see two lines. One red and the other green)
lewiszlw commented 1 year ago

Tried both, still segment fault for me.

irate-devil commented 1 year ago

Tried both, still segment fault for me.

Shucks. I can't think of anything else :(

mockersf commented 1 year ago

I was able to fix the issue for me with #8223