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 when drawing an image #1181

Closed
ToBinio opened this issue Mar 12, 2023 · 1 comment
Closed

Memory leak when drawing an image #1181

ToBinio opened this issue Mar 12, 2023 · 1 comment
Labels

Comments

@ToBinio
Copy link

ToBinio commented Mar 12, 2023

Describe the bug
The system memory & gpu memory leaks when drawing an image.
I think this only happens when drawing the image for the first time.

this bug could be connect to #1128

or maby i am doing something wrong

To Reproduce
run this code best in release mode

use ggez::graphics::{DrawParam, Image, ImageFormat};
use ggez::{event, graphics, Context, GameResult};
use image::{DynamicImage, EncodableLayout};

const IMG_SIZE: u32 = 8000;

struct MainState {}

impl MainState {
    fn new(_ctx: &mut Context) -> GameResult<MainState> {
        Ok(MainState {})
    }
}

impl event::EventHandler<ggez::GameError> for MainState {
    fn update(&mut self, _ctx: &mut Context) -> GameResult {
        Ok(())
    }

    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas =
            graphics::Canvas::from_frame(ctx, graphics::Color::from([0.1, 0.2, 0.3, 1.0]));

        let image = DynamicImage::new_rgb8(IMG_SIZE, IMG_SIZE);

        let image = Image::from_pixels(
            ctx,
            image.to_rgba8().as_bytes(),
            ImageFormat::Rgba8Unorm,
            IMG_SIZE,
            IMG_SIZE,
        );

        //comment out this line of code -> no memory leak
        // canvas.draw(&image, DrawParam::default());

        canvas.finish(ctx)?;

        Ok(())
    }
}

pub fn main() -> GameResult {
    let cb = ggez::ContextBuilder::new("super_simple", "ggez");
    let (mut ctx, event_loop) = cb.build()?;
    let state = MainState::new(&mut ctx)?;
    event::run(ctx, event_loop, state)
}

Expected behavior
No memory leak, image should be automatically dropped

Hardware and Software:

  • ggez version: 0.9.0-rc0 and current devel branch
  • OS: Windows 11
  • Graphics card: GTX 1660
@nobbele nobbele added the bug label Jun 27, 2023
This was referenced Jul 7, 2023
@Vixeliz
Copy link
Contributor

Vixeliz commented Jul 9, 2023

Should be fixed with 0.9.2 so i'm gonna go ahead and close feel free to tell me to reopen if the problem still exist.

@Vixeliz Vixeliz closed this as completed Jul 9, 2023
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

3 participants