-
-
Notifications
You must be signed in to change notification settings - Fork 323
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
load_texture() memory leak #421
Comments
Texture2D::delete might help But loading textures in the loop is usually not the best idea, it is almost always better to preload your resources once, before the game loop |
Thanks! Texture2D::delete definitely does help. But it's still strange to me why Pre-loading all resources is not an option for me, as I'm working with so many textures that if they were all loaded at once, they'd either take up several GB or exhaust memory entirely. So they have to be streamed. |
Are we interested in removing the I see the ReadMe's stated goal
And I'm not sure how that is guiding macroquad's development decisions. But as it stands, this issue introduces memory leaks, use after free, and double free bugs. The first of which can cause eventual crashing, and the ladder two of which can cause undefined behavior and software vulnerabilities. I support macroquad's attempt to be easy to program with. But as it stands, by making Summary
Note
|
use macroquad::prelude::*;
#[macroquad::main("test")]
async fn main() {
let texture1 = load_texture("./test.png").await.unwrap();
let texture2 = texture1.clone();
texture1.delete();
loop{
clear_background(GRAY);
let params = DrawTextureParams {
dest_size: Some(vec2(256., 256.)),
source: None,
rotation: 0.,
flip_x: false,
flip_y: false,
pivot: None,
};
draw_texture_ex(texture2, 0., 0., WHITE, params);
next_frame().await
}
} gets me this So currently |
I've discovered another memory leak
Unlike
The application I'm working on actually reloads some assets in response to settings changing. The user can change fonts/background images etc. It's a fire alarm so I picked Rust for this project because lives could be depending on this application so I'm very interested in getting this right. Would you accept a pull request to impl Drop for the font and Texture2D (and perhaps other things I find)? |
It seems like a different, maybe unrelated bug. What do you think? |
/// Delete GPU texture, leaving handle unmodified.
///
/// More high-level code on top of miniquad probably is going to call this in Drop implementation of some
/// more RAII buffer object.
///
/// There is no protection against using deleted textures later. However its not an UB in OpenGl and thats why
/// this function is not marked as unsafe
pub fn delete(&self) {
unsafe {
glDeleteTextures(1, &self.texture as *const _);
}
} I have decided to dig a bit out of curiosity, and in the |
Sorry, missed this comment! Yes, looks like |
It's very surprising to me that it's not better documented that Texture2d never unloads from memory. |
@omarandlorraine tarsila uses macroquad v0.3, but the I'm currently testing the latest versions of macroquad (a621304) and miniquad (not-fl3/miniquad@0fa2e35) and unfortunately the GPU memory is leaking I guess |
The above rust code will continue to fill ram until it is exhausted. Is this a memory leak or am I supposed to manually deallocate loaded textures? If so then how?
Macroquad version:
0.3.18
The text was updated successfully, but these errors were encountered: