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

Fix issues with RenderTarget leaking memory. #719

Merged
merged 1 commit into from
May 3, 2024

Conversation

profan
Copy link
Sponsor Contributor

@profan profan commented Apr 30, 2024

The memory leak issues just floating around were bothering me, and seemed simple enough to fix so figured why not :)

I also looked at #628 but couldn't actually reproduce the issue, so left that one alone for now.

src/texture.rs Outdated
@@ -340,6 +346,12 @@ pub struct RenderTarget {
pub render_pass: miniquad::RenderPass,
}

impl Drop for RenderTarget {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this lead to a use after free kind of error?

{
  let a = render_target.clone(); 
}
draw_texture(render_target);

Copy link
Sponsor Contributor Author

@profan profan May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, yeah assuming clone only copies the underlying resources in a shallow way, i guess it would yeah

it seems like both the Texture2D and RenderPass held is basically unmanaged, so you'd have to explicitly do the copy presumably in the Clone impl for RenderTarget

i'll have a look tonight and see if i can make this more sane/along with making an explicit test for the use-after-free case

Copy link
Sponsor Contributor Author

@profan profan May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i had another pass at it (creating a macroquad wrapper type for RenderPass), but it changes the public API which isn't very nice 🤔 plus the name overlaps with the miniquad name, seems like there's a bunch of little bits in the macroquad API that are still sort of partially unmanaged, seems hard to untangle without breaking backwards compatability

@profan
Copy link
Sponsor Contributor Author

profan commented May 2, 2024

Let me split this PR into two parts so that the Atlas leak issue can be fixed separately of this bigger RenderTarget/RenderPass issue quickly

... There we go, split the PR so discussion for the render target bit can continue here if needed

* Fix issue with RenderTarget leaking memory by adding a drop impl, reported in issue not-fl3#635
@profan profan changed the title Fix issues with Atlas, RenderTarget leaking memory. Fix issues with RenderTarget leaking memory. May 2, 2024
@not-fl3 not-fl3 merged commit 52cac9b into not-fl3:master May 3, 2024
6 checks passed
@not-fl3
Copy link
Owner

not-fl3 commented May 3, 2024

Thanks for PR!

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

Successfully merging this pull request may close these issues.

2 participants