raphamorim / rio

A hardware-accelerated GPU terminal emulator focusing to run in desktops and browsers.
https://raphamorim.io/rio
MIT License
3.51k stars 111 forks source link

thread 'main' panicked at /sugarloaf/src/context/mod.rs:100:14 #555

Open 0323pin opened 3 months ago

0323pin commented 3 months ago

Last time I've tried rio on NetBSD, it was at version 0.0.34

At the time, I faced this issue, https://github.com/raphamorim/rio/issues/376

Now, that there's v0.1.1, I thought I would try again.

The following three patches are required for it to build on NetBSD:

$NetBSD$

Add NetBSD support.

--- corcovado/src/sys/unix/kqueue.rs.orig   2023-12-10 20:06:10.635526974 +0000
+++ corcovado/src/sys/unix/kqueue.rs
@@ -346,6 +346,7 @@ impl Events {
             #[cfg(any(
                 target_os = "dragonfly",
                 target_os = "freebsd",
+                target_os = "netbsd",
                 target_os = "ios",
                 target_os = "macos"
             ))]
@@ -407,6 +408,7 @@ fn does_not_register_rw() {
 #[cfg(any(
     target_os = "dragonfly",
     target_os = "freebsd",
+    target_os = "netbsd",
     target_os = "ios",
     target_os = "macos"
 ))]
$NetBSD$

Add NetBSD support.

--- corcovado/src/sys/unix/ready.rs.orig    2023-12-10 20:09:23.686406007 +0000
+++ corcovado/src/sys/unix/ready.rs
@@ -98,6 +98,7 @@ const HUP: usize = 0b00_1000;
 #[cfg(any(
     target_os = "dragonfly",
     target_os = "freebsd",
+    target_os = "netbsd",
     target_os = "ios",
     target_os = "macos"
 ))]
@@ -106,6 +107,7 @@ const AIO: usize = 0b01_0000;
 #[cfg(not(any(
     target_os = "dragonfly",
     target_os = "freebsd",
+    target_os = "netbsd",
     target_os = "ios",
     target_os = "macos"
 )))]
@@ -176,6 +178,7 @@ impl UnixReady {
     #[cfg(any(
         target_os = "dragonfly",
         target_os = "freebsd",
+        target_os = "netbsd",
         target_os = "ios",
         target_os = "macos"
     ))]
@@ -186,6 +189,7 @@ impl UnixReady {
     #[cfg(not(any(
         target_os = "dragonfly",
         target_os = "freebsd",
+        target_os = "netbsd",
         target_os = "ios",
         target_os = "macos"
     )))]
@@ -318,6 +322,7 @@ impl UnixReady {
     #[cfg(any(
         target_os = "dragonfly",
         target_os = "freebsd",
+        target_os = "netbsd",
         target_os = "ios",
         target_os = "macos"
     ))]
@@ -330,6 +335,7 @@ impl UnixReady {
     #[cfg(not(any(
         target_os = "dragonfly",
         target_os = "freebsd",
+        target_os = "netbsd",
         target_os = "ios",
         target_os = "macos"
     )))]
$NetBSD$

Add NetBSD support.

--- teletypewriter/src/unix/mod.rs.orig 2023-12-10 19:54:05.309009040 +0000
+++ teletypewriter/src/unix/mod.rs
@@ -29,7 +29,7 @@ use std::sync::Arc;
 const TIOCSWINSZ: libc::c_ulong = 0x5414;
 #[cfg(all(target_os = "linux", target_env = "musl"))]
 const TIOCSWINSZ: libc::c_int = 0x5414;
-#[cfg(target_os = "freebsd")]
+#[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
 const TIOCSWINSZ: libc::c_ulong = 0x80087467;
 #[cfg(target_os = "macos")]
 const TIOCSWINSZ: libc::c_ulong = 2148037735;
@@ -288,7 +288,7 @@ pub fn create_termp(utf8: bool) -> libc:
         c_line: 0,
     };

-    #[cfg(any(target_os = "macos", target_os = "freebsd"))]
+    #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd"))]
     let mut term = libc::termios {
         c_iflag: libc::ICRNL | libc::IXON | libc::IXANY | libc::IMAXBEL | libc::BRKINT,
         c_oflag: libc::OPOST | libc::ONLCR,
@@ -306,7 +306,7 @@ pub fn create_termp(utf8: bool) -> libc:
         c_ospeed: Default::default(),
     };

-    #[cfg(not(target_os = "freebsd"))]
+    #[cfg(not(any(target_os = "freebsd", target_os = "netbsd")))]
     {
         // Enable utf8 support if requested
         if utf8 {
@@ -400,10 +400,10 @@ pub fn create_pty_with_spawn(
     columns: u16,
     rows: u16,
 ) -> Result<Pty, Error> {
-    #[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
+    #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd")))]
     let mut is_controling_terminal = true;

-    #[cfg(any(target_os = "macos", target_os = "freebsd"))]
+    #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd"))]
     let is_controling_terminal = true;

     let mut main: libc::c_int = 0;
@@ -452,7 +452,7 @@ pub fn create_pty_with_spawn(
         cmd
     };

-    #[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
+    #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd")))]
     {
         // If running inside a flatpak sandbox.
         // Must retrieve $SHELL from outside the sandbox, so ask the host.
@@ -879,9 +879,9 @@ pub fn foreground_process_name(main_fd: 
         pid = shell_pid as libc::pid_t;
     }

-    #[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
+    #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd")))]
     let comm_path = format!("/proc/{}/comm", pid);
-    #[cfg(target_os = "freebsd")]
+    #[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
     let comm_path = format!("/compat/linux/proc/{}/comm", pid);

     #[cfg(not(target_os = "macos"))]
@@ -907,9 +907,9 @@ pub fn foreground_process_path(
         pid = shell_pid as libc::pid_t;
     }

-    #[cfg(not(any(target_os = "macos", target_os = "freebsd")))]
+    #[cfg(not(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd")))]
     let link_path = format!("/proc/{}/cwd", pid);
-    #[cfg(target_os = "freebsd")]
+    #[cfg(any(target_os = "freebsd", target_os = "netbsd"))]
     let link_path = format!("/compat/linux/proc/{}/cwd", pid);

     #[cfg(not(target_os = "macos"))]

Unfortunately, it still won't run :(

thread 'main' panicked at /usr/pkgsrc/wip/rio/work/rio-0.1.1/sugarloaf/src/context/mod.rs:100:14:
Request adapter
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Exception: rio killed by signal abort trap (core dumped)

Setting RUST_BACKTRACE=full doesn't tell me more,

~> set-env RUST_BACKTRACE "full"
~> rio
thread 'main' panicked at /usr/pkgsrc/wip/rio/work/rio-0.1.1/sugarloaf/src/context/mod.rs:100:14:
Request adapter
stack backtrace:
   0:          0x117aad7 - <unknown>
   1:           0xd97d50 - <unknown>
   2:          0x119d09e - <unknown>
   3:          0x117a86d - <unknown>
   4:          0x1194840 - <unknown>
   5:          0x1194527 - <unknown>
   6:          0x1194d79 - <unknown>
   7:          0x117aeca - <unknown>
   8:          0x117acf6 - <unknown>
   9:          0x1194904 - <unknown>
  10:           0xcc5075 - <unknown>
  11:           0xd9c501 - <unknown>
  12:           0xcc54eb - <unknown>
  13:          0x1047b17 - <unknown>
  14:          0x106948a - <unknown>
  15:          0x1061dd2 - <unknown>
  16:           0xfd4143 - <unknown>
Exception: rio killed by signal abort trap (core dumped)

Neither does gdb

~> gdb rio rio.core
GNU gdb (GDB) 13.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64--netbsd".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from rio...
(No debugging symbols found in rio)
[New process 20260]
[New process 17631]
[New process 8626]
[New process 29333]
[New process 15316]
[New process 29538]
[New process 16473]
Core was generated by `rio'.
Program terminated with signal SIGABRT, Aborted.
#0  0x00007a5a1a8472aa in ?? ()
[Current thread is 1 (process 20260)]

Of course, as release is built without debugging symbols. But, I need the patches to build the package, so building with cargo only isn't as simple.

ktruss is probably a little more helpful.

[...]
 27681  27681 rio      mmap(0, 0x4000, 0x3, 0x1, 0xf, 0, 0x101069000) = 0x776838e36000
 27681  27681 rio      write(0x2, 0x11ec748, 0x8)  = 8
       "thread '"
 27681  27681 rio      write(0x2, 0x77683cfde008, 0x4) = 4
       "main"
 27681  27681 rio      write(0x2, 0x11ec758, 0xe)  = 14
       "' panicked at "
 27681  27681 rio      write(0x2, 0x117499c, 0x3f) = 63
       "/usr/pkgsrc/wip/rio/work/rio-0.1.1/sugarloaf/src/context/mod.rs"
 27681  27681 rio      write(0x2, 0x10eb890, 0x1)  = 1
       ":"
 27681  27681 rio      write(0x2, 0x7f7fff4b0345, 0x3) = 3
       "100"
 27681  27681 rio      write(0x2, 0x10eb890, 0x1)  = 1
       ":"
 27681  27681 rio      write(0x2, 0x7f7fff4b0346, 0x2) = 2
       "14"
 27681  27681 rio      write(0x2, 0x11ec766, 0x2)  = 2
       ":\n"
 27681  27681 rio      write(0x2, 0x77683bf6a970, 0xf) = 15
       "Request adapter"
 27681  27681 rio      write(0x2, 0x11ec768, 0x1)  = 1
       "\n"
 27681  27681 rio      write(0x2, 0x11ec769, 0x4e) = 78
       "note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace\n"
 27681  27681 rio      __sigprocmask14(0x3, 0x7f7fff4b05f0, 0) = 0
 27681  27681 rio      _lwp_self()                 = 27681
 27681  27681 rio      _lwp_kill(0x6c21, 0x6)      = 0
 27681  27681 rio      SIGABRT SIG_DFL
 27681  19547 rio      ___lwp_park60               Err#4 EINTR
 27681  21535 rio      ___lwp_park60               Err#4 EINTR
 27681  21786 rio      __kevent100                 Err#4 EINTR
 27681  11658 rio      ___lwp_park60               Err#4 EINTR
 27681  28920 rio      ___lwp_park60               Err#4 EINTR
 27681  11661 rio      ___lwp_park60               Err#4 EINTR

Any thoughts? Thanks!

0323pin commented 3 months ago

So, I've clone the repo locally, applied the above patches and built rio with the debug symbols on. Here's the resulting backtrace:

~> set-env RUST_BACKTRACE "full"
~> rio
thread 'main' panicked at /home/pin/Git/rio/sugarloaf/src/context/mod.rs:100:14:
Request adapter
stack backtrace:
   0:          0x26977c0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h64b379b49e1ac14c
   1:          0x26c62d3 - core::fmt::write::hffad184a3e8a29fd
   2:          0x267ff99 - std::io::Write::write_fmt::h898ad85f5400c6c1
   3:          0x26975a8 - std::sys_common::backtrace::print::hfd142b535fa244a2
   4:          0x2698229 - std::panicking::default_hook::{{closure}}::h0b2841cddcb5179d
   5:          0x2697ef2 - std::panicking::default_hook::hb55ff70a667c0912
   6:          0x2698781 - std::panicking::rust_panic_with_hook::hf0fd20f889dcc3a2
   7:          0x2698626 - std::panicking::begin_panic_handler::{{closure}}::hf70ee2d56df2cd9e
   8:          0x26979d9 - std::sys_common::backtrace::__rust_end_short_backtrace::h2bcae7246dcb03a5
   9:          0x2698377 - rust_begin_unwind
  10:           0x73c6a3 - core::panicking::panic_fmt::h54accd437c2365a4
  11:          0x26c855c - core::panicking::panic_display::h3f559986d8c35394
  12:           0x73c0ec - core::option::expect_failed::hfe05ab716a1704a1
  13:          0x1d7428c - core::option::Option<T>::expect::hf459028b2b901c2b
                               at /usr/pkgsrc/wip/rust179/work/rustc-1.79.0-src/library/core/src/option.rs:895:21
  14:           0x8a01a2 - sugarloaf::context::Context::new::{{closure}}::hdc78f2e28a5ed39b
                               at /home/pin/Git/rio/sugarloaf/src/context/mod.rs:93:23
  15:           0x7e1220 - sugarloaf::sugarloaf::Sugarloaf::new::{{closure}}::h1549472fcadf491d
                               at /home/pin/Git/rio/sugarloaf/src/sugarloaf.rs:120:50
  16:           0x7c470b - rio::screen::Screen::new::{{closure}}::h36417bcfd846877a
                               at /home/pin/Git/rio/frontends/rioterm/src/screen/mod.rs:159:10
  17:           0x88553a - rio::router::RouteWindow::new::{{closure}}::hf5609a978315b9b0
                               at /home/pin/Git/rio/frontends/rioterm/src/router/mod.rs:365:82
  18:           0x80907c - rio::sequencer::Sequencer::run::{{closure}}::hdfceb00f487f15c6
                               at /home/pin/Git/rio/frontends/rioterm/src/sequencer.rs:63:18
  19:           0x8587ea - rio::main::{{closure}}::h1f3516d14b586e2d
                               at /home/pin/Git/rio/frontends/rioterm/src/main.rs:149:50
  20:           0x794e13 - tokio::runtime::park::CachedParkThread::block_on::{{closure}}::h577a4f16ba7f1265
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/park.rs:281:63
  21:           0x794c6e - tokio::runtime::coop::with_budget::h88ae03db5d966fac
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:107:5
  22:           0x794c6e - tokio::runtime::coop::budget::h0618cc0523b111fa
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/coop.rs:73:5
  23:           0x794c6e - tokio::runtime::park::CachedParkThread::block_on::h917c79e45e27046e
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/park.rs:281:31
  24:           0x812772 - tokio::runtime::context::blocking::BlockingRegionGuard::block_on::hbd4155abba16ce0a
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/blocking.rs:66:9
  25:           0x780c79 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}::h32d608fba8768f78
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  26:           0x7f8dc5 - tokio::runtime::context::runtime::enter_runtime::h2a0d130d5b69c2c1
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/context/runtime.rs:65:16
  27:           0x780bfa - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h63782f3a604144f3
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  28:           0x806196 - tokio::runtime::runtime::Runtime::block_on::h2aaf9818535970a6
                               at /home/pin/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.37.0/src/runtime/runtime.rs:351:45
  29:           0x8d0fda - rio::main::h660e553ea9dbe216
                               at /home/pin/Git/rio/frontends/rioterm/src/main.rs:155:5
  30:           0x748b4b - core::ops::function::FnOnce::call_once::h281b9df121ef66e9
                               at /usr/pkgsrc/wip/rust179/work/rustc-1.79.0-src/library/core/src/ops/function.rs:250:5
  31:           0x804a4e - std::sys_common::backtrace::__rust_begin_short_backtrace::h2e97682ccb8e71b7
                               at /usr/pkgsrc/wip/rust179/work/rustc-1.79.0-src/library/std/src/sys_common/backtrace.rs:155:18
  32:           0x782561 - std::rt::lang_start::{{closure}}::hee1cb4c2a5c3093a
                               at /usr/pkgsrc/wip/rust179/work/rustc-1.79.0-src/library/std/src/rt.rs:159:18
  33:          0x2698267 - std::panicking::try::h89c5172be281790d
  34:          0x26a5938 - std::rt::lang_start_internal::h7cd5c2ba0d56d034
  35:           0x78253a - std::rt::lang_start::hb45a14bffd4e3e5a
                               at /usr/pkgsrc/wip/rust179/work/rustc-1.79.0-src/library/std/src/rt.rs:158:17
  36:           0x8d10ae - main
  37:           0x739375 - ___start
                               at /usr/src/lib/csu/common/crt0-common.c:349:2

Any ideas?

raphamorim commented 2 months ago

Thanks for the issue!

Hmmm, would be nice to patch those changes on Rio/"winit fork" as well. Regarding the second error you sent, looks the "Request adapter" couldn't be created, this happens when wgpu cannot create an adapter using vulkan/gl/...

0323pin commented 2 months ago

I can make a PR if you would like but, ...

would be nice to patch those changes on Rio/"winit fork" as well.

Where do I find that fork? I didn't see it on the branches you have here at github.

looks the "Request adapter" couldn't be created, this happens when wgpu cannot create an adapter using vulkan/gl/...

NetBSD doesn't have vulkan but, I've tried setting the wgpu environment variable to gl and that didn't help.

TornaxO7 commented 3 weeks ago

@0323pin

Where do I find that fork? I didn't see it on the branches you have here at github.

It's a directory in the repository. See here.

0323pin commented 3 weeks ago

Cheers @TornaxO7 ... I should have looked.

Also, this made me think about something else.

looks the "Request adapter" couldn't be created, this happens when wgpu cannot create an adapter using vulkan/gl/...

@raphamorim Would you spare me some grep and point me to where exactly the request is being made? Could be a ${PATH} issue. Worth discarding that otherwise.

raphamorim commented 3 weeks ago

@0323pin did you try using the renderer property? https://raphamorim.io/rio/docs/config/renderer

Something like this:

[renderer]
performance = "High"
backend = "GL"

I am curious though because if vulkan leads to error then Rio uses OpenGl as fallback.

raphamorim commented 3 weeks ago

Here's the piece of code https://github.com/raphamorim/rio/blob/4623f23b200e82a056391dd39a9eb9ba76027207/sugarloaf/src/context/mod.rs#L93-L132