MarkelZ / pygame-light2d

Fast 2D dynamic lighting engine for Pygame.
MIT License
20 stars 1 forks source link

Memory leak #5

Closed OlaKenji closed 12 months ago

OlaKenji commented 12 months ago

Hi, how is it going?

I just noticed that there is a memory leak associated with this light_engine. I see a steadily increase of usage of RAM for my project, but also when I run example1.py. I have this on my Mac and on my Windows.

Do you also have this issue?

MarkelZ commented 12 months ago

@OlaKenji Hi, thanks for letting me know!

I checked and Linux has the same issue. Apparently some OpenGL objects weren't getting freed when render_texture was called. I fixed it and it seems to have improved the situation. example1.py doesn't seem to be leaking anymore, but example2.py is still leaking (although slower than before). I'll look into it now.

I uploaded the fix to PyPI as version 2.0.2. Could you please install the new version with pip and try it on Widows and Mac? Hopefully example1.py shouldn't leak anymore.

MarkelZ commented 12 months ago

@OlaKenji Hi again, I just fixed the issue in example2.py. It was leaking memory because it was creating a temporary texture to render some text, but it wasn't freeing the texture data afterwards. I simply added a line with text_tex.release() and it doesn't leak anymore! example3.py had the same issue and now it's fixed.

Since the bug was in the examples and not the engine, version 2.0.2 should be leak free. Could you check if there are no leaks in your personal projects? I saw that you are working on a really cool game called "Happy Ville" where you use my engine. If you have leaks even with version 2.0.2 of my engine, you may need to call release() on the temporary textures after using them.

OlaKenji commented 12 months ago

Yes, I tried it but was still leaking. Calling release() seems to work though for both Mac and Windows. Thanks! :D

MarkelZ commented 12 months ago

@OlaKenji Awesome! Btw I tried running your game and it seems to not have any memory leaks on Linux either. I had to change some folder names to get it to run tho

OlaKenji commented 12 months ago

That's great it works on Linux as well. Do you know/remember which folders or in what way you needed to change them?

MarkelZ commented 11 months ago

@OlaKenji I just made a pull request with the changes: https://github.com/willhlm/happy_ville/pull/1