PistonDevelopers / PistonDevelopers/piston

Memory leak with texture.update

Open
#1,357 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

(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"

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 by running the minimal Rust reproduction from the issue with the listed piston, piston_window, image, Linux, and NVIDIA versions. Compare memory behavior with and without texture.update and with lazy events enabled; done means repeated renders no longer cause unbounded memory growth.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.