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 leak with texture.update #1357

Open
amarao opened this issue Sep 5, 2020 · 1 comment
Open

Memory leak with texture.update #1357

amarao opened this issue Sep 5, 2020 · 1 comment
Labels

Comments

@amarao
Copy link

amarao commented Sep 5, 2020

(My apology if I report it in the wrong place, user forum proposes to report it as a bug).

I've tried to debug my application, but found that there is a huge memory leak (~30GB in 30-40seconds). When I reduced program to smallest possible, I got this:

extern crate piston_window;
extern crate image as im;

use piston_window::*;
use piston::event_loop::Events;

fn main() {
    let x = 1920;
    let y  = 1080;
    let opengl = OpenGL::V3_2;
    let mut window: PistonWindow =
        WindowSettings::new("test", (x, y))
        .exit_on_esc(true)
        .graphics_api(opengl)
        .build()
        .unwrap();
    let mut texture_context = TextureContext {
        factory: window.factory.clone(),
        encoder: window.factory.create_command_buffer().into()
    };
    let mut events = Events::new(EventSettings::new().lazy(false));

    while let Some(e) = events.next(&mut window) {
        if let Some(_) = e.render_args() {
            let canvas = im::ImageBuffer::from_fn(x, y, |x, y| {
                    im::Rgba([12,13,14, 255])
            });
            let mut texture: G2dTexture = Texture::from_image(
                    &mut texture_context,
                    &canvas,
                    &TextureSettings::new()
                ).unwrap();
            texture.update(&mut texture_context, &canvas).unwrap();
            window.draw_2d(&e, |c, g, _device| {
                    image(&texture, c.transform, g);
            });
        }
    }
}

It causes memory leak like crazy.
If I comment out texture.update line, there is no leak. To reduce leak speed, change lazy from false to true.

My configuration is linux 5.7 (x86_64), nvidia-450.57-3, xserver 7.7.

Libraries:
piston = "0.49.0"
piston_window = "0.107.0"
image = "0.23.0"

@bvssvni
Copy link
Member

bvssvni commented Sep 6, 2020

@bvssvni bvssvni added the bug label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants