Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run the example code #245

Open
LaSpruca opened this issue Dec 16, 2020 · 1 comment
Open

Unable to run the example code #245

LaSpruca opened this issue Dec 16, 2020 · 1 comment

Comments

@LaSpruca
Copy link

Every time I try to run the example code. The application runs for a bit then dies, I then get this error message:

thread 'main' panicked at 'attempted to leave type \`platform::platform::x11::util::input::PointerState\` uninitialized, which is invalid

Here is my Cargo.toml:

[package]
name = "game_of_life"
version = "0.1.0"
authors = ["Nathan Hare <me@laspruca.nz>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
piston = "0.52.0"
piston2d-graphics = "0.39.0"
pistoncore-glutin_window = "0.67.0"
piston2d-opengl_graphics = "0.76.0"

And main.rs:

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

use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use piston::event_loop::{EventSettings, Events};
use piston::input::{RenderArgs, RenderEvent, UpdateArgs, UpdateEvent};
use piston::window::WindowSettings;

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.window_size[0] / 2.0, args.window_size[1] / 2.0);

        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() {
    // Change this to OpenGL::V2_1 if not working.
    let opengl = OpenGL::V3_2;

    // Create an Glutin window.
    let mut window: Window = WindowSettings::new("spinning-square", [200, 200])
        .graphics_api(opengl)
        .exit_on_esc(true)
        .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(args) = e.render_args() {
            app.render(&args);
        }

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

I am using:

  • Rust: rustc 1.48.0 (7eac88abb 2020-11-16)
  • OS: Ubuntu 20.04.1 LTS x86_64, kernel 5.4.0-58-generic
  • DE: KDE Plasma 5.18.5
  • Graphics Card: Nvidia GeForce GTX 1660 Super
  • Graphics Driver: Nvidia-driver- 450 (proprietary)
@emilhoeiriis
Copy link

I get the same error. I am using:

  • Rust: rustc 1.48.0 (7eac88abb 2020-11-16)
  • OS: Arch Linux x86_64
  • Kernel Release: 5.10.3-arch1-1
  • WM: bspwm
  • DE: None
  • Processor Type: Intel(R) Core(TM) i7-6770HQ CPU @ 2.60GHz
  • Graphics: Intel Corporation Iris Pro Graphics 580 (rev 09)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants