PistonDevelopers / PistonDevelopers/piston

"No backend is available" error with examples

Open
#1,236 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
4.7k
Forks
235
Avg merge
1m
Merged PRs (30d)
4

Description

I am trying to build and run an example from piston.rs, here is the code fore reference:

extern crate piston_window;

use piston_window::*;

fn main() {
    let mut window: PistonWindow = 
        WindowSettings::new("Hello Piston!", [640, 480])
        .exit_on_esc(true).build().unwrap();
    while let Some(e) = window.next() {
        window.draw_2d(&e, |c, g| {
            clear([1.0; 4], g);
            rectangle([1.0, 0.0, 0.0, 1.0], // red
                      [0.0, 0.0, 100.0, 100.0],
                      c.transform, g);
        });
    }
}

but get error:

     Running `target/debug/example`
thread 'main' panicked at 'No backend is available', /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.12.0/src/platform/linux/mod.rs:356:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:475
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:409
   6: winit::platform::platform::EventsLoop::new
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.12.0/src/platform/linux/mod.rs:356
   7: winit::EventsLoop::new
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.12.0/src/lib.rs:195
   8: glutin_window::GlutinWindow::new
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/pistoncore-glutin_window-0.47.0/src/lib.rs:102
   9: <glutin_window::GlutinWindow as window::BuildFromWindowSettings>::build_from_window_settings
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/pistoncore-glutin_window-0.47.0/src/lib.rs:449
  10: window::WindowSettings::build
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/pistoncore-window-0.32.0/src/lib.rs:392
  11: <piston_window::PistonWindow<W> as window::BuildFromWindowSettings>::build_from_window_settings
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/piston_window-0.80.0/src/lib.rs:152
  12: window::WindowSettings::build
             at /home/user/.local/share/cargo/registry/src/github.com-1ecc6299db9ec823/pistoncore-window-0.32.0/src/lib.rs:392
  13: example::main
             at src/main.rs:96
  14: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  15: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  16: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:106
  17: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  18: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  19: main
  20: __libc_start_main
  21: _start
             at ../sysdeps/x86_64/start.S:120

I am running NixOS, so problem may be with dynamically loading libraries. Is there a way to find out which
libs do I need?

As far as I can understand the problem is in XConnection::new function:

    pub fn new(error_handler: XErrorHandler) -> Result<XConnection, XNotSupported> {
        // opening the libraries
        let xlib = try!(ffi::Xlib::open());
        let xcursor = try!(ffi::Xcursor::open());
        let xrandr = try!(ffi::Xrandr_2_2_0::open());
        let xrandr_1_5 = ffi::Xrandr::open().ok();
        let xinput2 = try!(ffi::XInput2::open());
        let xlib_xcb = try!(ffi::Xlib_xcb::open());

        unsafe { (xlib.XInitThreads)() };
        unsafe { (xlib.XSetErrorHandler)(error_handler) };

        // calling XOpenDisplay
        let display = unsafe {
            let display = (xlib.XOpenDisplay)(ptr::null());
            if display.is_null() {
                return Err(XNotSupported::XOpenDisplayFailed);
            }
            display
        };

        Ok(XConnection {
            xlib: xlib,
            xrandr: xrandr,
            xrandr_1_5: xrandr_1_5,
            xcursor: xcursor,
            xinput2: xinput2,
            xlib_xcb: xlib_xcb,
            display: display,
            latest_error: Mutex::new(None),
        })
    }

I've tried to explicitly "install" all mentioned libs via nix-shell -p "[x11 gcc] ++ (with xorg; [libXcursor xrandr xinput libxcb])", but got the same error as above.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the example failure at src/main.rs:96 and the Linux backend panic reported at winit-0.12.0/src/platform/linux/mod.rs:356. Inspect XConnection::new and the listed dynamically loaded libraries, then reproduce the example in NixOS to determine whether the missing backend is caused by library loading or XOpenDisplay; done means documenting a confirmed cause and required setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
linux, nixos, rust
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.