Ok, so I made a 3D game for the jam, it’s dirty and quick, so maybe I just made some terrible optimization mistake, but I don’t think Lua is so easy to introduce memory leak. As some of you may have experienced, the game crashes and eats whole memory breaking systems. It happens also on my machine, but up to now I thought it’s because it’s crappy and not for 3D games. I would love to understand what the issue is, so please, help me investigate it
Source code: https://github.com/paweljarosz/horror_3d_game_mwdj_2023
Defold Beta 1.4.6
Remotery during normal gameplay, at the very beginning:
Then after some time game starts to hangs, drastically dropping fps to 1 and below, eats whole RAM and SWAP and crashes. There is definitely a memory leak:
I turned off previously opened application at point A (you see how high the ram got) it dropped immediately after closing game. I opened application again at point B and it’s visible the memory leak is from the beginning. At point C the image is captured:
Memory: over 95k!
LuaMem: over 700
I don’t understand fully the main window (an explanation of what is shown in Remotery would be nice!) but it looks like the most heavy scripts’s updates I would suspect are nothing actually.
Memory is very high, from start, so there is a problem at the beginning. I lowered all models to few hundreds-few thousands polygons, shrunk down textures to max 1024x1024, usually 512x512. I still though guess some models are problematic, but can’t find out which one or what’s the issue. I suspect the issue is with code that generates the map around - it creates world like tiles around player position, with factories spawning grass (2x2 quad) on bottom and up to 2 objects on top of the grass (1. tree or some other models + 2.eventually a sheet of paper - a 1x1 quad)). Enemy is spawned once and changes position (actually by removing it and factoring somewhere differently - it should be just changing position when I think about it now
It is perhaps regarding this code (scene.script
) creating world around using factories, but I don’t know what the issue might be. I wrote some simple instance counting, when factory.create() is called and watched it, but it never exceed some value that is regarding the maximum FOV I set.
EDIT:
No, my theory failed. I stoped recreating world - still memory leak. I didn’t created world at all - didn’t factored any other instances than player and collision box for ground - still memory leak!
EDIT2:
I even commented out all update functions, all timers… Still memory leak and nothing happens in the game.
EDIT3:
Ok, the problem must be in rendering script, because when I commented out whole body of update() in render script the memory is not raising after game starts. Found a place to investigate!