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

Memory allocation error when using Events::new(EventSettings::new()) #1260

Open
isaacg1 opened this issue Jan 2, 2019 · 0 comments
Open

Comments

@isaacg1
Copy link

isaacg1 commented Jan 2, 2019

When using an event loop created with Events::new(EventSettings::new()) , more and more meory is used up until the process aborts with an out of memory error. The problem can be avoided by switching to use window.next() instead.

Here's a reduced test case:

extern crate graphics;
extern crate opengl_graphics;
extern crate piston;
extern crate piston_window;

use opengl_graphics::OpenGL;
use piston::event_loop::*;
use piston::input::*;
use piston_window::{PistonWindow, WindowSettings};

const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];
const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0];

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

    let mut window: PistonWindow = WindowSettings::new("maze", [800, 600])
        .opengl(opengl)
        .exit_on_esc(true)
        .build()
        .unwrap();

    let mut events = Events::new(EventSettings::new());

    while let Some(event) = events.next(&mut window) {
        if let Some(_args) = event.render_args() {
            window.draw_2d(&event, |c, gl| {
                graphics::clear(BLACK, gl);

                for _row in 0..72 {
                    for _col in 0..120 {
                        let color = WHITE;
                        let box_rect =
                            graphics::rectangle::rectangle_by_corners(0.0, 0.0, 10.0, 10.0);
                        graphics::rectangle(color, box_rect, c.transform, gl);
                    }
                }
            });
        }
    }
}

The program aborts in about 2 minutes after attempting to allocate 8GB. If events is removed and window.next() is used in the while loop instead, the problem goes away.

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

1 participant