piston icon indicating copy to clipboard operation
piston copied to clipboard

Unable to run example

Open carymrobbins opened this issue 8 years ago • 8 comments

Getting the dreaded Couldn't find any pixel format that matches the criterias error when running the example.

Hardware: Dell XPS 9650 OS: Linux 4.13.3-1-ARCH Window Manager: xmonad 0.13-9

Backtrace

% RUST_BACKTRACE=1 cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/spinning-square`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Couldn\'t find any pixel format that matches the criterias."', /checkout/src/libcore/result.rs:860:4
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:380
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:611
   5: std::panicking::begin_panic_new
             at /checkout/src/libstd/panicking.rs:553
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:521
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:497
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:92
   9: core::result::unwrap_failed
             at /checkout/src/libcore/macros.rs:41
  10: <core::result::Result<T, E>>::unwrap
             at /checkout/src/libcore/result.rs:738
  11: spinning_square::main
             at src/main.rs:56
  12: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98
  13: std::rt::lang_start
             at /checkout/src/libstd/panicking.rs:458
             at /checkout/src/libstd/panic.rs:361
             at /checkout/src/libstd/rt.rs:59
  14: main
  15: __libc_start_main
  16: _start

Cargo.toml

[package]
name = "spinning-square"
version = "0.1.0"
authors = []

[[bin]]
name = "spinning-square"

[dependencies]
piston = "0.34.0"
piston2d-graphics = "0.22.0"
pistoncore-glutin_window= "0.40.0"
piston2d-opengl_graphics = "0.47.0"

src/main.rs

extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;

use piston::window::WindowSettings;
use piston::event_loop::*;
use piston::input::*;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{ GlGraphics, OpenGL };

pub struct App {
    gl: GlGraphics, // OpenGL drawing backend.
    rotation: f64   // Rotation for the square.
}

impl App {
    fn render(&mut self, args: &RenderArgs) {
        use graphics::*;

        const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
        const RED:   [f32; 4] = [1.0, 0.0, 0.0, 1.0];

        let square = rectangle::square(0.0, 0.0, 50.0);
        let rotation = self.rotation;
        let (x, y) = (
            (args.width / 2) as f64,
            (args.height / 2) as f64
        );
        self.gl.draw(args.viewport(), |c, gl| {
            // Clear the screen.
            clear(GREEN, gl);

            let transform =
                c.transform
                    .trans(x, y)
                    .rot_rad(rotation)
                    .trans(-25.0, -25.0);

            // Draw a box rotating around the middle of the screen.
            rectangle(RED, square, transform, gl);
        });
    }

    fn update(&mut self, args: &UpdateArgs) {
        // Rotate 2 radians per second.
        self.rotation += 2.0 * args.dt;
    }
}

fn main() {
    let opengl = OpenGL::V4_5;

    // Create a Glutin window.
    let mut window: Window =
        WindowSettings::new("spinning-square", [200, 200])
            .exit_on_esc(true)
            .samples(4)
            .opengl(opengl)
            .build()
            .unwrap();

    // Create a new game and run it.
    let mut app = App {
        gl: GlGraphics::new(opengl),
        rotation: 0.0
    };

    let mut events = Events::new(EventSettings::new());
    while let Some(e) = events.next(&mut window) {
        if let Some(r) = e.render_args() {
            app.render(&r);
        }

        if let Some(u) = e.update_args() {
            app.update(&u);
        }
    }
}

carymrobbins avatar Oct 09 '17 19:10 carymrobbins

I can confirm this issue, was about to post it and I have had this error for a month or so on two different machines Hardware: T440p with dedicated GPU OS: Linux 4.13.7-1-ARCH Window Manager: i3-wm 4.14.1-1 and Hardware: T450s with Intel GPU OS: some lts kernel, has been a while since I checked Window Manager: i3-wm 4.14.1-1

I did test it on the laptop of a friend though where it worked, waiting for him to give me the specs

fmagin avatar Oct 20 '17 06:10 fmagin

Can also confirm.
Kernel: LTS Kernel (4.9) Window Manager: KWin

Seems to be an issue with Arch Linux in general?

jD91mZM2 avatar Oct 20 '17 08:10 jD91mZM2

Friend confirmed his specs he is also running Arch with a NVidia GPU and the nouveau drivers (like me) but it works for him. This issue has also been discussed in #1202 the .srgb(false) does not work for me though

fmagin avatar Oct 20 '17 08:10 fmagin

Does an older version of OpenGL work on your machine?

bvssvni avatar Oct 20 '17 08:10 bvssvni

Note that I had this same issue with Amethyst; however, the problem has been fixed in master. Maybe there could be some coordination to figure out what causes this issue.

carymrobbins avatar Oct 20 '17 13:10 carymrobbins

Downgrading mesa to 17.1.X fixed it for me, as was suggested somewhere but I cant find that again :/ There was also some thread about this being a bug in mesa, will try to find it again

fmagin avatar Oct 20 '17 16:10 fmagin

This is a clear dupe of #1202.

est31 avatar Oct 20 '17 20:10 est31

This seems to have been fixed with the latest mesa 18.*. See https://github.com/PistonDevelopers/piston/issues/1202 for more information.

Cxarli avatar May 02 '18 16:05 Cxarli