zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.53k stars 3.03k forks source link

Crash on linux client due to NV_OPTIMUS issue. #8850

Closed VitorRamos closed 8 months ago

VitorRamos commented 8 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

cargo run results in panic before i can see anything in the screen:

Thread "main" panicked with "called `Result::unwrap()` on an `Err` value: Protocol(X(Match(RequestError { response_type: 0, error_code: 8, sequence: 141, bad_value: 50331652, minor_opcode: 4, major_opcode: 149, pad: 1 }), None))" at crates/gpui/src/platform/linux/x11/client.rs:98:81
   0: Zed::init_panic_hook::{closure#0}
             at crates/zed/src/main.rs:624:29
   1: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/alloc/src/boxed.rs:2029:9
      std::panicking::rust_panic_with_hook
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:783:13
   2: std::panicking::begin_panic_handler::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:657:13
   3: std::sys_common::backtrace::__rust_end_short_backtrace
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:171:18
   4: rust_begin_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:645:5
   5: core::panicking::panic_fmt
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/panicking.rs:72:14
   6: core::result::unwrap_failed
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1649:5
   7: <core::result::Result<core::option::Option<xcb::event::Event>, xcb::base::Error>>::unwrap
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/result.rs:1073:23
   8: <gpui::platform::linux::x11::client::X11Client>::new::{closure#0}
             at crates/gpui/src/platform/linux/x11/client.rs:98:49
   9: <core::cell::RefCell<calloop::sources::DispatcherInner<calloop::sources::generic::Generic<calloop::sources::generic::FdWrapper<alloc::rc::Rc<xcb::base::Connection>>, xcb::base::Error>, <gpui::platform::linux::x11::client::X11Client>::new::{closure#0}>> as calloop::sources::EventDispatcher<()>>::process_events::{closure#0}
             at /home/vitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/mod.rs:327:61
  10: <calloop::sources::generic::Generic<calloop::sources::generic::FdWrapper<alloc::rc::Rc<xcb::base::Connection>>, xcb::base::Error> as calloop::sources::EventSource>::process_events::<<core::cell::RefCell<calloop::sources::DispatcherInner<calloop::sources::generic::Generic<calloop::sources::generic::FdWrapper<alloc::rc::Rc<xcb::base::Connection>>, xcb::base::Error>, <gpui::platform::linux::x11::client::X11Client>::new::{closure#0}>> as calloop::sources::EventDispatcher<()>>::process_events::{closure#0}>
             at /home/vitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/generic.rs:290:9
  11: <core::cell::RefCell<calloop::sources::DispatcherInner<calloop::sources::generic::Generic<calloop::sources::generic::FdWrapper<alloc::rc::Rc<xcb::base::Connection>>, xcb::base::Error>, <gpui::platform::linux::x11::client::X11Client>::new::{closure#0}>> as calloop::sources::EventDispatcher<()>>::process_events
             at /home/vitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/sources/mod.rs:326:9
  12: <calloop::loop_logic::EventLoop<()>>::dispatch_events
             at /home/vitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/loop_logic.rs:445:31
  13: <calloop::loop_logic::EventLoop<()>>::dispatch::<core::option::Option<core::time::Duration>>
             at /home/vitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/loop_logic.rs:559:9
  14: <calloop::loop_logic::EventLoop<()>>::run::<<gpui::platform::linux::platform::LinuxPlatform as gpui::platform::Platform>::run::{closure#0}, core::option::Option<core::time::Duration>>
             at /home/vitor/.cargo/registry/src/index.crates.io-6f17d22bba15001f/calloop-0.12.4/src/loop_logic.rs:596:13
  15: <gpui::platform::linux::platform::LinuxPlatform as gpui::platform::Platform>::run
             at crates/gpui/src/platform/linux/platform.rs:129:9
  16: <gpui::app::App>::run::<Zed::main::{closure#3}>
             at crates/gpui/src/app.rs:143:9
  17: Zed::main
             at crates/zed/src/main.rs:120:5
  18: <fn() as core::ops::function::FnOnce<()>>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5
  19: std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/sys_common/backtrace.rs:155:18
  20: std::rt::lang_start::<()>::{closure#0}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:166:18
  21: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:284:13
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal::{{closure}}
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:48
      std::panicking::try::do_call
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:552:40
      std::panicking::try
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panicking.rs:516:19
      std::panic::catch_unwind
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/panic.rs:142:14
      std::rt::lang_start_internal
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:148:20
  22: std::rt::lang_start::<()>
             at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/std/src/rt.rs:165:17
  23: main
  24: __libc_start_call_main
             at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  25: __libc_start_main_impl
             at ./csu/../csu/libc-start.c:392:3
  26: _start

After some investigation, i found that the issue is in blade, in the current revision it selects the first graphics card it found in this case intel integrated graphics card: [2024-03-04T15:16:55+01:00 INFO blade_graphics::hal::init] Adapter "Intel(R) UHD Graphics 630 (CFL GT2)" [2024-03-04T15:16:55+01:00 INFO blade_graphics::hal::init] No ray tracing extensions are supported This will crash in systems with nv_optimus setup (intel + nvidia), lucky this was fixed in a newer rev: https://github.com/kvark/blade/commit/30c4fa41f1476e932b9c1f104665b0a2904f94c4

After upgrading to this revision everything worked fine:

From 4d9761b4100c4c3bc4e0f8e9d1e7b1453cbe72d7 Mon Sep 17 00:00:00 2001
From: vitorramos <ramos.vitor89@gmail.com>
Date: Mon, 4 Mar 2024 19:37:52 +0100
Subject: [PATCH] Linux: blade: Rejecting Intel for not presenting when Nvidia
 is present NV_OPTIMUS

---
 Cargo.lock                                       | 4 ++--
 Cargo.toml                                       | 4 ++--
 crates/gpui/src/platform/linux/wayland/window.rs | 1 +
 crates/gpui/src/platform/linux/x11/window.rs     | 1 +
 4 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 6ba0cd82a..27ea2a276 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1451,7 +1451,7 @@ dependencies = [
 [[package]]
 name = "blade-graphics"
 version = "0.3.0"
-source = "git+https://github.com/kvark/blade?rev=e9d93a4d41f3946a03ffb76136290d6ccf7f2b80#e9d93a4d41f3946a03ffb76136290d6ccf7f2b80"
+source = "git+https://github.com/kvark/blade?rev=43721bf42d298b7cbee2195ee66f73a5f1c7b2fc#43721bf42d298b7cbee2195ee66f73a5f1c7b2fc"
 dependencies = [
  "ash",
  "ash-window",
@@ -1481,7 +1481,7 @@ dependencies = [
 [[package]]
 name = "blade-macros"
 version = "0.2.1"
-source = "git+https://github.com/kvark/blade?rev=e9d93a4d41f3946a03ffb76136290d6ccf7f2b80#e9d93a4d41f3946a03ffb76136290d6ccf7f2b80"
+source = "git+https://github.com/kvark/blade?rev=43721bf42d298b7cbee2195ee66f73a5f1c7b2fc#43721bf42d298b7cbee2195ee66f73a5f1c7b2fc"
 dependencies = [
  "proc-macro2",
  "quote",
diff --git a/Cargo.toml b/Cargo.toml
index 682908e2f..07bb05625 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -197,8 +197,8 @@ async-compression = { version = "0.4", features = ["gzip", "futures-io"] }
 async-tar = "0.4.2"
 async-trait = "0.1"
 bitflags = "2.4.2"
-blade-graphics = { git = "https://github.com/kvark/blade", rev = "e9d93a4d41f3946a03ffb76136290d6ccf7f2b80" }
-blade-macros = { git = "https://github.com/kvark/blade", rev = "e9d93a4d41f3946a03ffb76136290d6ccf7f2b80" }
+blade-graphics = { git = "https://github.com/kvark/blade", rev = "43721bf42d298b7cbee2195ee66f73a5f1c7b2fc" }
+blade-macros = { git = "https://github.com/kvark/blade", rev = "43721bf42d298b7cbee2195ee66f73a5f1c7b2fc" }
 blade-rwh = { package = "raw-window-handle", version = "0.5" }
 chrono = { version = "0.4", features = ["serde"] }
 clap = "4.4"
diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rs
index 11e1743b0..9af7aa1ed 100644
--- a/crates/gpui/src/platform/linux/wayland/window.rs
+++ b/crates/gpui/src/platform/linux/wayland/window.rs
@@ -83,6 +83,7 @@ impl WaylandWindowInner {
                     gpu::ContextDesc {
                         validation: false,
                         capture: false,
+                        overlay: false,
                     },
                 )
             }
diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rs
index f60f7f19b..7c719c9ac 100644
--- a/crates/gpui/src/platform/linux/x11/window.rs
+++ b/crates/gpui/src/platform/linux/x11/window.rs
@@ -237,6 +237,7 @@ impl X11WindowState {
                     gpu::ContextDesc {
                         validation: false,
                         capture: false,
+                        overlay: false,
                     },
                 )
             }
-- 
2.34.1

Environment

Notebook with nvidia optimus setup Linux awesome wm x11 client

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

If you only need the most recent lines, you can run the zed: open log command palette action to see the last 1000.

No response

davidbuzz commented 8 months ago

once its merged... this should fix it... https://github.com/zed-industries/zed/pull/8811 . I tripped over the nvidia/optimus/prime issue a week ago, and its root cause appears to be this: https://github.com/kvark/blade/pull/92