Page 1 of 1

Severe memory leak upon rendering player

Posted: Sat Feb 29, 2020 5:53 am
by Ethan_Pixelate
OH NO! Its the EVIL Mario sprite OF DOOM!, long story short, rendering mario sprite on my raspberry pi causes mysterious freezing, then find out on windows that its a memory leak, a memory leak so severe that it jumped from around 70MB of ram usage to 4GB of ram, nearly choking all the free memory i have, reigning it's unholy wrath down on my poor innocent computer with the fury of a thousand gods. I dont know how to fix this and i have looked at similar cases with no luck :( . The .love is attached below (it is bundled with the memory leak so be careful and dont let it dissintegrate your ram)

Navigation around the project:

main.lua simply loads in the game, because its also possible to launch a crappy chunk editor by running it on the command line via "-editor"
game.lua the actual game file
Assets_Scripts/TilesetLoader.lua not the problem, but it is responsible for slicing tilesets (including mario sprite) into tiles
Assets_Scripts/AnimatedDrawables.lua still not the problem but also slices images up tileset-style, but for animation
Assets_Images/Mario.png the mario sprite being sliced

Mario.png gets sliced at game.lua:58
Mario gets rendered at game.lua:381

Re: Severe memory leak upon rendering player

Posted: Sat Feb 29, 2020 2:00 pm
by zorg
Hi and welcome to the forums.

Okay, i had a look, but the project's huge already...

While i didn't see any too obvious issues regarding creating tons of löve objects each update (which still might be the case though), i did notice your LoadTileset function creating both ImageDatas *and* Images for each tile you iterate over;

That in and of itself is both very RAM and VRAM heavy;

Consider not caring about ImageDatas at all, and rather just load your whole tileset in as an Image, along with using one or more SpriteBatch objects so things won't waste that much space.

Re: Severe memory leak upon rendering player

Posted: Sat Feb 29, 2020 2:45 pm
by pgimeno
In line 381 you're calling love.draw, which is the same event you're in. That should be love.graphics.draw.

Re: Severe memory leak upon rendering player

Posted: Sat Feb 29, 2020 5:03 pm
by Ethan_Pixelate
zorg wrote: Sat Feb 29, 2020 2:00 pm Hi and welcome to the forums.

Okay, i had a look, but the project's huge already...

While i didn't see any too obvious issues regarding creating tons of löve objects each update (which still might be the case though), i did notice your LoadTileset function creating both ImageDatas *and* Images for each tile you iterate over;

That in and of itself is both very RAM and VRAM heavy;

Consider not caring about ImageDatas at all, and rather just load your whole tileset in as an Image, along with using one or more SpriteBatch objects so things won't waste that much space.
Ill consider trying something like that, i never even knew what sprite batches were until i read this post and looked it up. Thank you!
pgimeno wrote: Sat Feb 29, 2020 2:45 pm In line 381 you're calling love.draw, which is the same event you're in. That should be love.graphics.draw.
Well. That explains alot. Thank you!

:awesome: